实现拖动table标题实现改变td的大小

<html> 
<title>拖动列宽的表格</title> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<style type="text/css"><!-- 
.bg td{ 
    font-size:12px; 
    text-align:left; 
    line-height:15px; 
    height:20px; 
} 
.bg td.tit{ 
background-color:#e2e2e2; 
height:17px; 
    text-align:center; 
    line-height:15px; 
} 
.bg td.num{ 
background-color:#e2e2e2; 
    text-align:right; 
    line-height:15px; 
    width:30px; 
    height:22px; 
} 
.resizeDivClass{ 
text-align:right; 
width:1px; 
margin:0px 0 0px 0; 
background:#fff; 
border:0px; 
float:right; 
cursor:e-resize; 
} 
--></style> 
<script language="javascript"><!-- 
function MouseDownToResize(obj){ 
    setTableLayoutToFixed(); 
    obj.mouseDownX=event.clientX; 
    obj.pareneTdW=obj.parentElement.offsetWidth; 
    obj.pareneTableW=theObjTable.offsetWidth; 
    obj.setCapture(); 
} 
function MouseMoveToResize(obj){ 
if(!obj.mouseDownX) return false; 
var newWidth=obj.pareneTdW*1+event.clientX*1-obj.mouseDownX; 
if(newWidth>10) 
{ 
    var theObjTable = document.getElementById("theObjTable"); 
    obj.parentElement.style.width = newWidth; 
    theObjTable.style.width=obj.pareneTdW*1+event.clientX*1-obj.mouseDownX; 
    } 
} 
function MouseUpToResize(obj){ 
    obj.releaseCapture(); 
    obj.mouseDownX=0; 
} 
function setTableLayoutToFixed() 
{ 
var theObjTable = document.getElementById("theObjTable"); 
if(theObjTable.style.tableLayout=='fixed') return; 
var headerTr=theObjTable.rows[0]; 
for(var i=0;i<headerTr.cells.length;i++) 
{ 
headerTr.cells[i].styleOffsetWidth=headerTr.cells[i].offsetWidth; 
} 

for(var i=0;i<headerTr.cells.length;i++) 
{ 
headerTr.cells[i].style.width=headerTr.cells[i].styleOffsetWidth; 
} 
theObjTable.style.tableLayout='fixed'; 
} 
function theObjTable(o,a,b,c){ 
    var t=document.getElementById(o).getElementsByTagName("tr"); 
    for(var i=0;i<t.length;i++){ 
        t[i].style.backgroundColor=(t[i].sectionRowIndex%2==0)?a:b; 
        t[i].οnclick=function(){ 
            if(this.x!="1"){ 
            }else{ 
                this.x="0"; 
                this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b; 
            } 
        } 
        t[i].οnmοuseοver=function(){ 
            if(this.x!="1")this.style.backgroundColor=c; 
        } 
        t[i].οnmοuseοut=function(){ 
            if(this.x!="1")this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b; 
        } 
    } 
} 
// --></script> 
<body> 
<table width="100%" class="bg" border=1 cellspacing=0 bordercolorlight="#7b7b7b" bordercolordark="#efefef" id="theObjTable"> 
<tr> 
<td class="num">序号</td> 
<td width="100px" class="tit"> 
<span class="resizeDivClass" onMouseDown="MouseDownToResize(this);" onMouseMove="MouseMoveToResize(this);" onMouseUp="MouseUpToResize(this);"></span> 
公司名称 
</td> 
<td class="tit"> 
<span class="resizeDivClass" onMouseDown="MouseDownToResize(this);" onMouseMove="MouseMoveToResize(this);" onMouseUp="MouseUpToResize(this);"></span> 
订单客户 
</td> 
<td class="tit"> 
<span class="resizeDivClass" onMouseDown="MouseDownToResize(this);" onMouseMove="MouseMoveToResize(this);" onMouseUp="MouseUpToResize(this);"></span> 
部门 
</td> 
<td class="tit"> 
<span class="resizeDivClass" onMouseDown="MouseDownToResize(this);" onMouseMove="MouseMoveToResize(this);" onMouseUp="MouseUpToResize(this);"></span> 
业务员 
</td> 
<td class="tit"> 
<span class="resizeDivClass" onMouseDown="MouseDownToResize(this);" onMouseMove="MouseMoveToResize(this);" onMouseUp="MouseUpToResize(this);"></span> 
交款方式 
</td> 
</tr> 
<tr> 
<td class="num" >1</td> 
<td >中国电信</td> 
<td >订单客户名称</td> 
<td >广告部</td> 
<td >王天一</td> 
<td >现金</td> 
</tr> 
<tr> 
<td class="num" >2</td> 
<td >中国移动</td> 
<td >订单客户名称</td> 
<td >营销部</td> 
<td >李小红</td> 
<td >信用卡</td> 
</tr> 
<tr> 
<td class="num" >3</td> 
<td >中国联通</td> 
<td >订单客户名称</td> 
<td >市场部</td> 
<td >王老二</td> 
<td >银行卡</td> 
</tr> 
</table> 
<script language="javascript"><!-- 
//senfe("表格名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景"); 
theObjTable("theObjTable","#c0c0c0","#fff","#a3a2a2"); 
// --></script> 
</body> 
</html> 
IE only from:http://www.jb51.net/article/21201.htm
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 可以使用 Bootstrap Table 的扩展插件 `bootstrap-table-sticky-header` 来实现表头固定,使用 `bootstrap-table-resizable` 插件来实现列宽可拖动改变宽度大小。 首先,需要在页面中引入 `bootstrap-table-sticky-header.css` 和 `bootstrap-table-sticky-header.js` 插件文件以及 `bootstrap-table-resizable.js` 插件文件。例如: ```html <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-table-sticky-header/dist/bootstrap-table-sticky-header.css"> <script src="https://cdn.jsdelivr.net/npm/bootstrap-table-sticky-header/dist/bootstrap-table-sticky-header.js"></script> <script src="https://rawgit.com/wenzhixin/bootstrap-table-resizable/master/src/bootstrap-table-resizable.js"></script> ``` 然后,在表格初始化时,需要将 `stickyHeader` 和 `resizable` 选项设置为 `true`,如下所示: ```javascript $('#table').bootstrapTable({ stickyHeader: true, // 开启表头固定 resizable: true, // 开启列宽可拖动改变 columns: [ // 列配置 ], data: [ // 数据 ] }); ``` 这样就可以在表格实现表头固定和列宽可拖动改变的效果了。 ### 回答2: Bootstrap table 是一款基于Bootstrap框架的表格插件,可以用于展示数据和操作表格。要实现表头固定和列宽可拖动改变宽度大小,可以使用Bootstras Table的一些功能和插件。 首先,为了实现表头固定,可以使用Bootstrap Table的fixedHeader插件。这个插件可以将表格的表头固定在顶部,即使表格有滚动条也能保持表头可见。可以通过添加fixedHeader: true的属性来启用这个功能。 其次,为了实现列宽可拖动改变宽度大小,可以使用Resizable插件。这个插件可以让列的宽度可调整,用户可以拖动列的边界改变宽度大小。可以通过添加resizable: true的属性来启用这个功能。 示例代码如下: ```html <table id="myTable" data-resizable="true" data-fixed-header="true"> <thead> <tr> <th data-field="id">ID</th> <th data-field="name">Name</th> <th data-field="age">Age</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>John</td> <td>25</td> </tr> <tr> <td>2</td> <td>Jane</td> <td>30</td> </tr> </tbody> </table> <script> $(document).ready(function() { $('#myTable').bootstrapTable({ fixedHeader: true, resizable: true }); }); </script> ``` 上述示例代码中,我们创建了一个带有ID、Name和Age三列的表格,并启用了表头固定和列宽可调整功能。用户可以拖动列边界来改变列的宽度大小,而表头会一直保持在表格的顶部可见。 希望这个回答对您有帮助! ### 回答3: Bootstrap table是一种用于创建漂亮且响应式数据表格的开源前端框架。要实现表头固定和列宽可拖动改变宽度大小的功能,可以使用Bootstrap table的相关插件。以下是实现的步骤: 1. 表头固定:使用Bootstrap table的fixedHeader插件。这个插件可以使表格的表头在滚动时固定在页面顶部。只需要在表格初始化时启用该插件即可。 2. 列宽可拖动改变大小:使用Bootstrap table的resizable插件。这个插件可以让列的宽度可以通过拖动改变。首先,需要在表格初始化时启用该插件。然后,在表头中的每个列中添加一个可拖动的区域,例如使用col-resizable类。最后,使用CSS样式指定这个可拖动区域的样式和大小。 综上所述,要实现Bootstrap table的表头固定和列宽可拖动改变大小的功能,可以使用fixedHeader和resizable两个插件。这些插件能够使表格更加灵活和易于使用,并提供更好的用户体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值