Layer.js实现表格溢出内容省略号显示,悬停显示全部的方法
2019-09-16 17:31
2101 查看
Index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>表格内容溢出省略号显示</title> <style type="text/css"> .contain { font-family: ‘ Microsoft YaHei '; margin: 15px auto; width: 900px; } table { border: 1px solid #e3e6e8; border-collapse: collapse; display: table; table-layout: fixed; text-align: center; width: 100%; } th, td { border: 1px solid #e3e6e8; height: 38px; line-height: 38px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } th { background-color: #189AD6; color: #fff; } .layui-layer { word-break: break-all; word-wrap: break-word; } </style> <!--relate to this page javascript--> <script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.js"></script> <script src="https://cdn.bootcss.com/layer/3.1.0/layer.js"></script> </head> <body> <div class="contain"> <table> <thead> <th>货币</th> <th>本周收盘</th> <th>上周收盘</th> <th>涨跌</th> <th>幅度</th> </thead> <tbody> <tr> <td>EURGBP“EUR/GBP settled above 0.90 on Friday as the bounce in EUR/USD helped the lift the pair further into the 0.90 territory”.</td> <td>0.86333333333393222222</td> <td>0.88945555555555555553</td> <td>-203333333333333333111</td> <td>-2.3166%</td> </tr> <tr> <td>EURGBP</td> <td>0.8693</td> <td>0.8894</td> <td>-201</td> <td>-2.31%</td> </tr> <tr> <td>EURGBP</td> <td>0.8693</td> <td>0.8894</td> <td>-201</td> <td>-2.31%</td> </tr> </tbody> </table> </div> <script type="text/javascript"> $(function() { $("td").on("mouseenter", function() { //js主要利用offsetWidth和scrollWidth判断是否溢出。 //在这里scrollWidth是包含内容的完全高度,offsetWidth是当前表格单元格的宽度。 if (this.offsetWidth < this.scrollWidth) { var that = this; var text = $(this).text(); window.layer.tips(text, that, { tips: 1, time: 2000 }); } }); }) </script> </body> </html>
效果如图:
以上这篇Layer.js实现表格溢出内容省略号显示,悬停显示全部的方法就是小编分享给大家的全部内容了,希望能给大家一个参考
您可能感兴趣的文章:
相关文章推荐
- 表格溢出内容省略号显示,悬停显示全部
- 基于JS代码实现当鼠标悬停表格上显示这一格的全部内容
- js实现当鼠标移到表格上时显示这一格全部内容的代码
- JS实现点击链接切换显示隐藏内容的方法
- JS/jQuery实现默认显示部分文字点击按钮显示全部内容
- vue制作表格,内容过多用“...”代替,鼠标悬停显示全部内容,vue分页,模板
- JS实现控制表格行内容垂直对齐的方法
- js实现当页面文字过长时用...表示,当点击时显示全部内容
- JS实现控制表格内指定单元格内容对齐的方法
- JS实现默认显示部分文字点击按钮显示全部内容
- JS实现左右拖动改变内容显示区域大小的方法
- JS实现隐藏同级元素后只显示JS文件内容的方法
- css特效实现html表格显示部分内容,当鼠标移上去显示全部。
- JS实现点击循环切换显示内容的方法
- html table表格导出excel的方法 html5 table导出Excel HTML用JS导出Excel的五种方法 html中table导出Excel 前端开发 将table内容导出到excel HTML table导出到Excel中的解决办法 js实现table导出Excel,保留table样式
- JS实现左右拖动改变内容显示区域大小的方法
- JS实现控制表格只显示行边框或者只显示列边框的方法
- JS/jQuery实现默认显示部分文字点击按钮显示全部内容
- text-overflow:ellipsis溢出显示省略实现方法
- 当显示的页面内容太长时,需要省略号代替时,通过自定义标签来实现方法