javascript sort table & merge same column
˵Ã÷£º
appendChild()
ÎÒ²âÊԵĽá¹û£º
1 appendChild() ±í¸ñÖÐËùÓÐÐÐÑ»·ÉÏÒÆÒ»ÐÐºó£¬ ÓÃеģ¨ÐУ©Ìæ»»ÁË ±í¸ñµÄÄ©ÐÐ £»Ï൱ÓÚÌæ»»Á˱í¸ñµÄµÚÒ»ÐУ¬²¢Ñ»·ÉÏÒÆÒ»ÐÐ
2 ²»¸Ä±ä ±í¸ñµÄ×Ü ÐÐÊý
insertRow()
1 insertRow() ÔÚ±í¸ñÖвåÈëÒ»ÐУ¬±í¸ñ×ÜÐÐÊéÔöÒ»
2 insertRow(index) index=0 , ÔÚ±íÍ·Ôö¼Ó£¬ index=-1, ÔÚ±íβÔö¼Ó¡£
deleteRow()
1 deleteRow(0) ɾ³ý±íÍ·µÚÒ»ÐУ¬ µÚ¶þÐбäΪµÚÒ»ÐУ» Òò´Ëɾ³ý±íÍ·Ç°nÐУ¬¿ÉÒÔÑ»·n´Îµ÷ÓÃdeleteRow(0)
Example: Sort table & Merge same Column
1¡£ Break Table: ±éÀú±í¸ñ£¬Èç¹ûÅÅÐòÁÐ µÄijTD°üº¬¶à¸öÖµ£¬ ÐèÒª²ð·ÖΪ¶àÐУ¨Ê¹ÓÃinsertRow(-1)£» index=-1ÊÇÒòΪ±ãÀû¹ý³ÌʹÓÃÔÓбí¸ñµÄÐÐÊý½øÐбéÀú£¬ÈôÔÚ±íÍ·²åÈëÐÐÔò±éÀúʧЧ£©
2¡£ Sort Table£º
a,½«±í¸ñÖеĴúÅÅÐòÐб£´æµ½Êý×éArrayOrigÖУ¬
b: ÅÅÐòÊý×éArrayOrig
c:±éÀúÊý×éArrayOrig£¬ºÏ²¢ÏàͬÁУ¬Éú³ÉArrayDest£¨×¢ÒâºÏ²¢¹ý³ÌÖÐÐèÒª±£Ö¤×´Ì¬£¬ÊôÐÔ·ûºÏÐèÇó£©
d: ±éÀúArrayDest£¬Ê¹ÓÃappendChild() Ìí¼Óµ½±í¸ñÖС£
3¡£ Delete Table£º ÒòΪappendChild()²»»á¸Ä±ä±í¸ñÐÐÊý£¬Òò´ËÊÊÓà count=ArrayOrig.length - ArrayDest.length Ñ»·µ÷ÓÃdeleteRow(0)ɾ³ý±íÇ°countÐÐ
ÒÔÏÂΪ ÍøÉÏµÄ Ò»Ð©×ÊÁÏ£º
http://zxjava.javaeye.com/blog/193926
1¡¢inserRow()ºÍinsertCell()º¯Êý
insertRow(index)£ºindex´Ó0¿ªÊ¼
Õâ¸öº¯Êý½«ÐÂÐÐÌí¼Óµ½indexµÄÄÇÒ»ÐÐÇ°£¬±ÈÈçinsertRow(0),Êǽ«ÐÂÐÐÌí¼Óµ½µÚÒ»ÐÐ֮ǰ¡£Ä¬ÈϵÄinsertRow()º¯ÊýÏ൱ÓÚ insertRow(-1)£¬½«ÐÂÐÐÌí¼Óµ½±íµÄ×îºó¡£Ò»°ãÎÒÃÇÔÚʹÓõÄʱºò¶¼ÊÇ£ºobjTable.insertRow(objTable.rows.length).¾ÍÊÇΪ±í¸ñobjTableÔÚ×îºóÐÂÔöÒ»ÐС£
insertCell()ºÍinsertRowµÄÓ÷¨Ïàͬ£¬ÕâÀï¾Í²»ÔÙ˵ÁË¡£
2¡¢deleteRow()ºÍdeleteCell()·½·¨
deleteRow(index)£ºindex´Ó0¿ªÊ¼
ɾ³ýÖ¸¶¨Î»ÖõÄÐк͵¥Ôª¸ñ¡£Òª´«ÈëµÄ²ÎÊý£ºIndexÊÇÐÐÔÚ±í¸ñÖеÄλÖ㬿ÉÒÔÏÂÃæµÄ·½·¨È¡µÃÈ»ºóȥɾ³ý£º
var row=document.getElementById("Row_Id");
var index=row.rowIndex;
objTable.deleteRow(index);
ɾ³ý±í¸ñµÄÐеÄʱºò£¬Èç¹ûÄãɾ³ýÁËijһÐУ¬ÄÇô±í¸ñÐÐÊýÊÇÂíÉϾͱ仯µÄ£¬ËùÒÔÈç¹ûÄãҪɾ³ý±í¸ñµÄËùÓÐÐУ¬ÏÂÃæµÄ´úÂëÊÇ´íÎóµÄ£º
function clearRow(){
objTable= document.getElementById("myTable");
for( var i=1; i<objTable.rows.length ; i++ )
{
tblObj.deleteRow(i);
}
}
Õâ¶Î´úÂëҪɾ³ý
Ïà¹ØÎĵµ£º
±Õ°ü£¨closure£©ÊÇJavascriptÓïÑÔµÄÒ»¸öÄѵ㣬ҲÊÇËüµÄÌØÉ«£¬ºÜ¶à¸ß¼¶Ó¦Óö¼ÒªÒÀ¿¿±Õ°üʵÏÖ¡£
ÏÂÃæ¾ÍÊÇÎÒµÄѧϰ±Ê¼Ç£¬¶ÔÓÚJavascript³õѧÕßÓ¦¸ÃÊǺÜÓÐÓõġ£
Ò»¡¢±äÁ¿µÄ×÷ÓÃÓò
ÒªÀí½â±Õ°ü£¬Ê×ÏȱØÐëÀí½âJavascriptÌØÊâµÄ±äÁ¿×÷ÓÃÓò¡£
±äÁ¿µÄ×÷ÓÃÓòÎ޷ǾÍÊÇÁ½ÖÖ£ºÈ«¾Ö±äÁ¿ºÍ¾Ö²¿±äÁ¿¡£
JavascriptÓïÑÔµÄÌØÊâÖ®´¦£¬¾ÍÔÚÓ ......
‘µãÕý³£Á´½Ó·½·¨ºÜ¶à£¬ÕâÀï½éÉܵÄÊÇ×Ô¶¯µãJavaScriptÁ´½Ó
Function RunJS(scripts)
‘VB ×Ô¶¯µãÍøÒ³ÖеÄJavascriptÁ´½Ó
Dim Document
On Error GoTo ErrHandle
......
ÉùÃ÷:Õâ¸öÊÇÍøÉϵÄ×ÊÁÏ,²»¹ýÎÒÔںܴó³Ì¶ÈÉϽøÐÐÁË×Ô¼ºµÄ˵Ã÷½éÉÜ,Ï£Íû´ó¼Ò»áϲ»¶¿´
1.document.write("Êä³öÄÚÈÝ");ΪÊä³öÓï¾ä
2.JSÖеÄ×¢ÊÍΪµ¥ÐÐ//ºÍ¶àÐÐ/**/
3.´«Í³µÄHTMLÎĵµË³ÐòÊÇ:document->html->(head,body)
4.Ò»¸öä¯ÀÀÆ÷´°¿ÚÖеÄDOM˳ÐòÊÇ:window->(navigator,screen,history,location,docume ......
//»ñÈ¡ä¯ÀÀÆ÷µÄ¿íºÍ¸ß£¨¶àÖÖä¯ÀÀÆ÷£©
function getNavWidthandHeightInfo()
{
var s = "";
s += " ÍøÒ³¿É¼ûÇøÓò¿í£º"+ document.body.clientWidth;
s += " ÍøÒ³¿É¼ûÇøÓò¸ß£º"+  ......