日期:2014-05-17  浏览次数:20654 次

jsp中如何可以手动拖动表格列宽
各位,我现在做了一个表格动态显示数据库中的数据,但是如果后台数据字段较长,则在前台显示时由于表格列宽的限制一部分内容会被覆盖住,所以我想把表格做成类似于PL_SQL中表格显示的那样,可以拖动列宽,希望哪位能提供方法帮忙解决这个问题,先谢谢了!

------解决方案--------------------
帮个你了个,只能支持ie
HTML code
 
<html>
<title>无标题文档 </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
.bg table{
  font-size:12px;
color:#000000;
}
.bg td{
  font-size:12px;
color:#000000;
text-align:left;
line-height:15px;
height:20px;
}
.bg td.tit{
  background-color:#e2e2e2;
  color:#000;
  height:17px;
text-align:center;
line-height:15px;
}
.bg td.num{
  background-color:#e2e2e2;
  color:#000;
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.parentNode.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';
}
</script>
<script language="javascript"> <!--
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].onclick=function(){
if(this.x!="1"){
}else{
this.x="0";
this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
}
}
t[i].onmouseover=function(){
if(this.x!="1")this.style.backgroundColor=c;
}
t[i].onmouseout=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" >