Java Web can drag table cell size HTML, drag the mouse to change the table size

Source: Internet
Author: User
Tags eval java web

Effect diagram: Drag a vertical bar with a color position to drag the table width left and right, changing the width of the top and bottom

Disadvantage: Drag point extremely accurate, want to drag once to have patience

Then Post code:

HTML code



<meta http-equiv= "Content-type" content= "text/html"; charset=gb2312 ">


. Resizedivclass









. TD1 {





color: #0000ff;

pos:expression (This.offsetleft*1+this.offsetwidth*1+tab.offsetleft);



<script language=javascript>

function mousedowntoresize (obj) {




obj.setcapture ();


function mousemovetoresize (obj) {

if (!OBJ.MOUSEDOWNX) return false;

var newwidth=obj.parenetdw*1+event.clientx*1-obj.mousedownx;

if (newwidth>0)

  { = newwidth;*1+event.clientx*1-obj.mousedownx;

for (var i=1 i<=tab.rows (0). cells.length;i++) {

var obj = eval ("mydiv" +i); = Obj.parentelement.offsetleft*1+obj.parentelement.offsetwidth* Setleft;//obj.par;




function mouseuptoresize (obj) {

Obj.releasecapture ();



function init () {

var tempstr = "";

for (var i=1 i<=tab.rows (0). cells.length;i++) {

tempstr = ' <div id= ' mydiv ' +i+ ' "class=" Resizedivclass "onmousedown=" mousedowntoresize (this); " Onmousemove= "Mousemovetoresize (This)," onmouseup= "mouseuptoresize (this);" ></div> ';

tab.rows (0). Cells (i-1). InnerHTML = tab.rows (0). Cells (i-1). Innerhtml+tempstr;

var obj = eval ("mydiv" +i); =;





<body onload= "init ()" >

<table id=tab style= "table-layout:fixed;" >


<TD valign=top class= "TD1" ><nobr> change table column width change </nobr></td>

<td valign=top class= "TD1" ><nobr> change table column width change </nobr></td>

<td valign=top class= "TD1" ><nobr> change table column width change </nobr></td>



<td class= "TD1" ><nobr> change table column width </nobr></td>

<td class= "TD1" ><nobr> change table column width </nobr></td>

<td class= "TD1" ><nobr> change table column width </nobr></td>





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.