javascript+dhtml Implementation Table Drag

Source: Internet
Author: User
Dhtml|javascript

<style>

body{

font-size:9pt;

}

table,th,td{

font-size:9pt;

}

. lsittalbe{

table-layout:fixed;

width:30%;

Border-collapse:collapse;

Border-color: #507010;

Color: #003300;

}

. pageda{

Font-family:webdings;

font-size:12pt;

Color: #CCCCCC;

Cursor:default;

}

. pageua{

Font-family:webdings;

font-size:12pt;

}

. even{

Background: #e8f8d0;

}

. odd{

Background: #f8fcf0;

}

. header{

BACKGROUND:A0DC40;

color:003300;

}

</style>

<title>javascript+dhtml Implementation Table Drag demo</title>

<meta name= "generator" content= "EditPlus" >

<meta name= "Author" content= "Hunk Dong" >

<body>

<br>

javascript+dhtml Implementation Table Drag hold <b> column 1</b> can drag

<table class= "Lsittalbe" border= "1" cellspacing= "1" cellpadding= "1" onmousemove= "MouseMove ()" >

<tr class= "Header" >

<th width= "10%" > Column 1</th>

<th width= "10%" > Column 2</th>

<th width= "40%" > Column 3</th>

<th width= "40%" > Column 4</th>

<tr>

<tr class= "Even" id= "tr_1" >

<TD style= "Cursor:move" title= "Hold and drag" >1</TD>

<TD ><input class=inputstyle id=chktaskitem_3 type=checkbox value=3

<TD ><input class=inputstyle id=txttaskname_3 type=txttaskname size=25 name=txttaskname value= "Test1" > </TD>

<TD >test1</TD>

</tr>

<tr class= "Odd" id= "tr_2" >

<TD style= "Cursor:move" title= "Hold and drag" >2</TD>

<TD ><input class=inputstyle id=chktaskitem4 type=checkbox value=4

<TD ><input class=inputstyle id=txttaskname_4 type=txttaskname size=25 name=txttaskname value= "Test2" > </TD>

<TD >test2</TD>

</tr>



<tr class= "Even" id= "tr_3" >

<TD style= "Cursor:move" title= "Hold and drag" >3</TD>

<TD ><input class=inputstyle id=chktaskitem_5 type=checkbox value=5

<TD ><input class=inputstyle id=txttaskname_5 type=txttaskname size=25 name=txttaskname value= "Test3" > </TD>

<TD >test3</TD>

</tr>

</table>

</body>



<script language= "JavaScript" >

var Srcrowindex;

var Targetrowindex;

var Bdragmode;

var Objdragitem;

var El;



function Window.onload () {

Initadditionalelements ();

}



function initadditionalelements () {

Objdragitem = document.createelement ("DIV");

With (Objdragitem.style) {

BackgroundColor = "Buttonshadow";

cursor = "Default";

Position = "absolute";

Filter = "Progid:DXImageTransform.Microsoft.Alpha (style=0,opacity=50)";

ZIndex = 3001;

display = "None";

}

Window.document.body.insertAdjacentElement ("Afterbegin", Objdragitem);

}



function MouseDown () {

el = window.event.srcElement;

if (el==null| | el.tagname!= "TD") return false;

if (el.cellindex!=0 | | el.parentnode.rowindex<2) return FALSE;

Srcrowindex = el.parentelement;

Bdragmode = true;

if (objdragitem!=null) {

With (Objdragitem) {

InnerHTML = El.parentElement.innerHTML;

Style.height = El.parentElement.offsetHeight;

Style.width = El.parentElement.offsetWidth;

}

}

El.setcapture ();

}

function MouseUp () {

if (el==null | | el.cellindex!=0 | | el.parentnode.rowindex<2) return FALSE;

Targetrowindex = el.parentelement;

Srcrowindex.swapnode (Targetrowindex);



Bdragmode = false;

ObjDragItem.style.display = "None";

}



function MouseMove () {

el = window.event.srcElement;

Window.event.cancelBubble = false;

Clix = Window.event.clientX;

Cliy = Window.event.clientY;

if (Bdragmode && objdragitem!=null) {

With (Objdragitem) {

Style.display = "";

Style.posleft = Clix +1;

Style.postop = CLIY-OFFSETHEIGHT/2;

}

}

}

</script>



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: info-contact@alibabacloud.com 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.