代码驿站移动版
频道导航
HTML/Xhtml
CSS
JavaScript
HTML5
PHP教程
ASP.NET
正则表达式
AJAX
ThinkPHP
Yii
MySQL
MariaDB
Oracle
MongoDB
Redis
DedeCMS
PHPCMS
帝国CMS
WordPress
Discuz
其它CMS
Zend Studio
Sublime
Notepad
Dreamweaver
Windows
Linux
Nginx
Apache
IIS
CentOS
Ubuntu
Debian
网站优化
工具资源
PHP源码
ASP.NET源码
其它源码
图标素材
按钮素材
字体素材
DedeCMS模板
帝国CMS模板
PHPCMS模板
WordPress模板
Discuz!模板
单页模板
开发软件下载
服务器软件下载
广告投放
联系我们
版权申明
软件编程
网页前端
移动开发
数据库
服务器
脚本语言
PHP代码
JAVA代码
Python代码
Android代码
当前位置:
主页
>
网页前端
>
JavaScript代码
>
表格头固定而列可滚动的效果
时间:2020-12-08 22:36:01 | 栏目:
JavaScript代码
| 点击:次
对于经常需要表格头部不东,而列表可以滚动,多用于数据比较多的情况,方便查看
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>表格头固定而列可滚动的效果-脚本之家</title></head> <style type="text/css"> body { font-family: "arial", "helvetica", "sans-serif", ""; font-size: 9pt; margin: 0px; scrollbar-face-color:#efefe7; scrollbar-highlight-color:#ffffff; scrollbar-3dlight-color:#a5a5a5; scrollbar-darkshadow-color:#a5a5a5; scrollbar-shadow-color:#d6d6ce; scrollbar-arrow-color:#003184; scrollbar-track-color:#deded6; } table { font-family: "arial", "helvetica", "sans-serif",""; font-size: 9pt; line-height: 150%; color: #000000; } .display-tb2 { border-right: #808080 1px solid; border-top: #808080 1px solid; border-left: #808080 1px solid; border-bottom: #808080 1px solid; border:0; cellpadding:2; cellspacing:0; margin-top:2px; border-collapse:collapse; } div.tableContainer { overflow-x:auto; width:760px; dyn-behavior:expression( onscroll == null? (onscroll = function(){ if(event.srcElement.scrollLeft == event.srcElement.oldScroll) return; var oGridBody = document.getElementById("order_GridBody"); oGridBody.style.width = parseInt(event.srcElement.clientWidth) + event.srcElement.scrollLeft + "px"; event.srcElement.oldScroll == event.srcElement.scrollLeft; }):true, onmousedown == null? (onmousedown = function(){ if(self.currentTH != null) return; var obj = document.elementFromPoint(event.x,event.y); var objL = document.elementFromPoint(event.x - 1,event.y); if(obj.tagName.toLowerCase() == "th") { if(objL.tagName.toLowerCase() == "th") { obj = objL; } if(obj.className == "fixed") return; self.currentX = event.x; self.currentTH = obj.childNodes[0]; self.currentTH.setCapture(); } }):true, onmouseup == null? (onmouseup = function(){ if(self.currentTH != null) { self.currentTH.releaseCapture(); self.currentTH = null; } }):true, onmousemove == null? (onmousemove = function(){ if(self.currentTH != null) { var width = Math.round(parseInt(self.currentTH.clientWidth) + event.x - self.currentX); if(width < 0) width = 0; var dt = parseInt(self.currentTH.style.width) - width; self.currentTH.style.width = width; __resizeCell(self.currentTH.columnIndex,self.currentTH.style.width); self.currentX = event.x; } }):true, self.__resizeCell == null? (self.__resizeCell = function(idx, width){ var cells = document.getElementById("order_GridBody_Cells"); var rows = cells.childNodes; var i = 0; for (var i = 0; i < rows.length; i++) { var cell = rows[i].childNodes[idx].childNodes[0]; var resetPattern = /style=[^\s\t\n]+/; cell.outerHTML = cell.outerHTML.toString().replace(resetPattern, "style='width:" +width + "'"); } }):true ) } div.bodyContainer { height:250px; width:760px; overflow-x:hidden; overflow-y:auto; } div.gridCell_standard { width:100px; overflow:hidden; nw:expression(this.noWrap=true); margin-left: 0px; margin-right: 1px; padding-left: 2px; cursor:default; } div.gridCell_narrow { width:30px; overflow:hidden; margin-left: 0px; margin-right: 1px; padding-left: 2px; nw:expression(this.noWrap=true); cursor:default; } th { border-right: #a4a6a4 1px solid; border-top: #a4a6a4 1px solid; border-left: #a4a6a4 1px solid; border-bottom: #a4a6a4 1px solid; background-image: url(images/default/headerbg.gif); color:#ffffff; font-style:normal; font-weight:normal; height:20px; cursor:col-resize; dyn-behavior:expression( ondblclick == null? (ondblclick = function() { var src = event.srcElement; if(event.srcElement.tagName.toLowerCase()!="div") { src = src.childNodes[0]; } src.style.width = ""; __resizeCell(src.columnIndex,src.clientWidth); }):true ) } th.fixed { border-right: #a4a6a4 1px solid; border-top: #a4a6a4 1px solid; border-left: #a4a6a4 1px solid; border-bottom: #a4a6a4 1px solid; background-image: url(images/default/headerbg.gif); color:#ffffff; font-style:normal; font-weight:normal; height:20px; cursor:default; } tr.odd { border-right: #a4a6a4 1px solid; border-top: #a4a6a4 0px solid; border-left: #a4a6a4 0px solid; border-bottom: #a4a6a4 1px solid; noWrap; } tr.even { border-right: #a4a6a4 1px solid; border-top: #a4a6a4 0px solid; border-left: #a4a6a4 0px solid; border-bottom: #a4a6a4 1px solid; } td.odd_even { border-right: #a4a6a4 1px solid; border-top: #a4a6a4 1px solid; border-left: #a4a6a4 1px solid; border-bottom: #a4a6a4 1px solid; noWrap; } td.select-cell { border-right: #a4a6a4 1px solid; border-top: #a4a6a4 1px solid; border-left: #a4a6a4 1px solid; border-bottom: #a4a6a4 1px solid; } th{ color:#ff0000; } </style> <body bgcolor="F6F6F6" style="padding:10 10 10 10"> <div class="tableContainer" id="order_Container"> <!--动态表格--> <table cellpadding="0" class="display-tb2" style="margin-top: 2px;" cellspacing="0" border="0" id="order"> <tr> <td> <table cellpadding="0" class="display-tb2" style="margin-top: 0px;" cellspacing="0" border="0"> <thead> <th class="fixed"><div columnIndex="0" class="gridCell_narrow">选择</div></th> <th><div columnIndex="1" class="gridCell_standard">订单编号</div></th> <th><div columnIndex="2" class="gridCell_standard">订货日期</div></th> <th><div columnIndex="3" class="gridCell_standard">订货单位</div></th> <th><div columnIndex="4" class="gridCell_standard">订单类别</div></th> <th><div columnIndex="5" class="gridCell_standard">产品类别</div></th> <th><div columnIndex="6" class="gridCell_standard">版本号</div></th> <th><div columnIndex="7" class="gridCell_standard">订货金额</div></th> <th><div columnIndex="8" class="gridCell_standard">订单状态</div></th> </thead> </table> </td> </tr> <!--<tfoot> 共3页 </tfoot>--> <tbody> <tr class="odd"> <td colspan="9"> <div id="order_GridBody" class="bodyContainer"> <table cellpadding="0" class="display-tb2" style="margin-top: 0px;" cellspacing="0" border="0"> <tbody id="order_GridBody_Cells"> <tr class="even"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="2" /></div></td> <td class="odd_even"><div class="gridCell_standard">DJPH001</div></td> <td class="odd_even"><div class="gridCell_standard">2005-02-02</div></td> <td class="odd_even"><div class="gridCell_standard">19</div></td> <td class="odd_even"><div class="gridCell_standard">直销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">5</div></td> <td class="odd_even"><div class="gridCell_standard">12.0000</div></td> <td class="odd_even"><div class="gridCell_standard">已取消</div></td></tr> <tr class="even"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="3" /></div> </td> <td class="odd_even"><div class="gridCell_standard">DJPH001</div></td> <td class="odd_even"><div class="gridCell_standard">2005-02-02</div></td> <td class="odd_even"><div class="gridCell_standard">19</div></td> <td class="odd_even"><div class="gridCell_standard">购销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">5</div></td> <td class="odd_even"><div class="gridCell_standard">21.0000</div></td> <td class="odd_even"><div class="gridCell_standard"> </div></td></tr> <tr class="odd"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="4" /></div> </td> <td class="odd_even"><div class="gridCell_standard">DJPH889</div></td> <td class="odd_even"><div class="gridCell_standard">2005-02-02</div></td> <td class="odd_even"><div class="gridCell_standard">0</div></td> <td class="odd_even"><div class="gridCell_standard">购销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">5</div></td> <td class="odd_even"><div class="gridCell_standard">21.0000</div></td> <td class="odd_even"><div class="gridCell_standard">已取消</div></td></tr> <tr class="even"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="5" /></div> </td> <td class="odd_even"><div class="gridCell_standard">DJPH889</div></td> <td class="odd_even"><div class="gridCell_standard">2005-02-02</div></td> <td class="odd_even"><div class="gridCell_standard">0</div></td> <td class="odd_even"><div class="gridCell_standard">直销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">5</div></td> <td class="odd_even"><div class="gridCell_standard">1.0000</div></td> <td class="odd_even"><div class="gridCell_standard"> </div></td></tr> <tr class="odd"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="6" /></div> </td> <td class="odd_even"><div class="gridCell_standard">tytutyjh465456</div></td> <td class="odd_even"><div class="gridCell_standard">2005-02-02</div></td> <td class="odd_even"><div class="gridCell_standard">0</div></td> <td class="odd_even"><div class="gridCell_standard">购销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">0</div></td> <td class="odd_even"><div class="gridCell_standard">21.0000</div></td> <td class="odd_even"><div class="gridCell_standard">生产部已审核</div></td></tr> <tr class="even"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="7" /></div> </td> <td class="odd_even"><div class="gridCell_standard">KDSZ2005050698</div></td> <td class="odd_even"><div class="gridCell_standard">2005-05-05</div></td> <td class="odd_even"><div class="gridCell_standard">-1</div></td> <td class="odd_even"><div class="gridCell_standard">分销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">10.2</div></td> <td class="odd_even"><div class="gridCell_standard">21.0000</div></td> <td class="odd_even"><div class="gridCell_standard">生产部已审核</div></td></tr> <tr class="odd"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="8" /></div> </td> <td class="odd_even"><div class="gridCell_standard">KDSZ2005050698</div></td> <td class="odd_even"><div class="gridCell_standard">2005-05-05</div></td> <td class="odd_even"><div class="gridCell_standard">-1</div></td> <td class="odd_even"><div class="gridCell_standard">分销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">10.2</div></td> <td class="odd_even"><div class="gridCell_standard">12.0000</div></td> <td class="odd_even"><div class="gridCell_standard">总代已审核</div></td></tr> <tr class="even"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="9" /></div> </td> <td class="odd_even"><div class="gridCell_standard">KDSZ2005050698</div></td> <td class="odd_even"><div class="gridCell_standard">2005-05-05</div></td> <td class="odd_even"><div class="gridCell_standard">-1</div></td> <td class="odd_even"><div class="gridCell_standard">分销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">10.2</div></td> <td class="odd_even"><div class="gridCell_standard">32.0000</div></td> <td class="odd_even"><div class="gridCell_standard">已取消</div></td></tr> <tr class="odd"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="10" /></div> </td> <td class="odd_even"><div class="gridCell_standard">KDSZ2005050698</div></td> <td class="odd_even"><div class="gridCell_standard">2005-05-05</div></td> <td class="odd_even"><div class="gridCell_standard">-1</div></td> <td class="odd_even"><div class="gridCell_standard">分销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">10.2</div></td> <td class="odd_even"><div class="gridCell_standard">12.0000</div></td> <td class="odd_even"><div class="gridCell_standard"> </div></td></tr> <tr class="even"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="11" /></div> </td> <td class="odd_even"><div class="gridCell_standard">KDSZ2005050698</div></td> <td class="odd_even"><div class="gridCell_standard">2005-05-05</div></td> <td class="odd_even"><div class="gridCell_standard">-1</div></td> <td class="odd_even"><div class="gridCell_standard">分销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">10.2</div></td> <td class="odd_even"><div class="gridCell_standard">12.0000</div></td> <td class="odd_even"><div class="gridCell_standard"> </div></td></tr> <tr class="odd"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="12" /></div> </td> <td class="odd_even"><div class="gridCell_standard">KDSZ2005050698</div></td> <td class="odd_even"><div class="gridCell_standard">2005-05-05</div></td> <td class="odd_even"><div class="gridCell_standard">-1</div></td> <td class="odd_even"><div class="gridCell_standard">分销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">10.2</div></td> <td class="odd_even"><div class="gridCell_standard">12.0000</div></td> <td class="odd_even"><div class="gridCell_standard">已取消</div></td></tr> <tr class="even"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="13" /></div> </td> <td class="odd_even"><div class="gridCell_standard">KDSZ2005050698</div></td> <td class="odd_even"><div class="gridCell_standard">2005-05-05</div></td> <td class="odd_even"><div class="gridCell_standard">-1</div></td> <td class="odd_even"><div class="gridCell_standard">分销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">10.2</div></td> <td class="odd_even"><div class="gridCell_standard">12.0000</div></td> <td class="odd_even"><div class="gridCell_standard">已取消</div></td></tr> <tr class="odd"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="14" /></div> </td> <td class="odd_even"><div class="gridCell_standard">KDSZ2005050698</div></td> <td class="odd_even"><div class="gridCell_standard">2005-05-05</div></td> <td class="odd_even"><div class="gridCell_standard">-1</div></td> <td class="odd_even"><div class="gridCell_standard">分销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">10.2</div></td> <td class="odd_even"><div class="gridCell_standard">12.0000</div></td> <td class="odd_even"><div class="gridCell_standard">已取消</div></td></tr> <tr class="even"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="15" /></div> </td> <td class="odd_even"><div class="gridCell_standard">KDSZ2005050698</div></td> <td class="odd_even"><div class="gridCell_standard">2005-05-05</div></td> <td class="odd_even"><div class="gridCell_standard">-1</div></td> <td class="odd_even"><div class="gridCell_standard">分销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">10.2</div></td> <td class="odd_even"><div class="gridCell_standard">21.0000</div></td> <td class="odd_even"><div class="gridCell_standard">已取消</div></td></tr> <tr class="odd"> <td width="30px" class="select-cell"> <div class="gridCell_narrow"><input type="checkbox" name="id" value="16" /></div> </td> <td class="odd_even"><div class="gridCell_standard">KDSZ2005050698</div></td> <td class="odd_even"><div class="gridCell_standard">2005-05-05</div></td> <td class="odd_even"><div class="gridCell_standard">-1</div></td> <td class="odd_even"><div class="gridCell_standard">分销</div></td> <td class="odd_even"><div class="gridCell_standard">KIS</div></td> <td class="odd_even"><div class="gridCell_standard">10.2</div></td> <td class="odd_even"><div class="gridCell_standard">12.0000</div></td> <td class="odd_even"><div class="gridCell_standard">已取消</div></td></tr> </tbody> </table> </div> </td> </tr> </tbody> </table> <div style="height:15px"></div> </div> </body> </html>
[Ctrl+A 全选 注:
引入外部Js需再刷新一下页面才能执行
]
您可能感兴趣的文章:
JavaScript常见事件处理程序实例总结
url传递的参数值中包含&时,url自动截断问题的解决方法
Javascript的匿名函数小结
javascript上下左右定时滚动插件
Javascript别踩白块儿(钢琴块儿)小游戏实现代码
相关文章
11-08
兼容浏览器的js事件绑定函数(详解)
11-27
Javascript实例教程(19) 使用HoTMetal(2)
11-23
Webpack中loader打包各种文件的方法实例
10-05
javascript判断图片是否加载完成的方法推荐
11-22
在javascript中执行任意html代码的方法示例解读
JQuery
VUE
AngularJS
MSSql
MySQL
MongoDB
Redis
Linux
Tomcat
Nginx
网站首页
广告投放
联系我们
版权申明
联系站长