Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

javascript²Ù×÷±í¸ñ

ÀûÓÃjsÀ´¶¯Ì¬´´½¨±í¸ñÓÐÁ½ÖÖ¸ñʽ£¬appendChild()ºÍinsertRow¡¢insertCell()¡£Á½ÖÖ·½Ê½Æäʵ²î²»¶à£¬µ«µÚÒ»ÖÖÓпÉÄÜÔÚIEÉÏÓÐÎÊÌ⣬ËùÒÔÍƼö´ó¼ÒʹÓõڶþÖÖÁË£¬Ö±½Ó˵°É¡£
1¡¢inserRow()ºÍinsertCell()º¯Êý
insertRow()º¯Êý¿ÉÒÔ´ø²ÎÊý£¬ÐÎʽÈçÏ£º
insertRow(index)£ºindex´Ó0¿ªÊ¼
Õâ¸öº¯Êý½«ÐÂÐÐÌí¼Óµ½indexµÄÄÇÒ»ÐÐÇ°£¬±ÈÈçinsertRow(0),Êǽ«ÐÂÐÐÌí¼Óµ½µÚÒ»ÐÐ֮ǰ¡£Ä¬ÈϵÄinsertRow()º¯ÊýÏ൱ÓÚinsertRow(-1)£¬½«ÐÂÐÐÌí¼Óµ½±íµÄ×îºó¡£Ò»°ãÎÒÃÇÔÚʹÓõÄʱºò¶¼ÊÇ£ºobjTable.insertRow(objTable.rows.length).¾ÍÊÇΪ±í¸ñobjTableÔÚ×îºóÐÂÔöÒ»ÐС£
insertCell()ºÍinsertRowµÄÓ÷¨Ïàͬ£¬ÕâÀï¾Í²»ÔÙ˵ÁË¡£
2¡¢deleteRow()ºÍdeleteCell()·½·¨
deleteRow()º¯Êý¿ÉÒÔ´ø²ÎÊý£¬ÐÎʽÈçÏ£ºdeleteRow(index)£ºindex´Ó0¿ªÊ¼
ºÍÉÏÃæÁ½¸ö·½·¨²î²»¶àµÄÒâ˼£¬¾ÍÊÇɾ³ýÖ¸¶¨Î»ÖõÄÐк͵¥Ôª¸ñ¡£Òª´«ÈëµÄ²ÎÊý£ºIndexÊÇÐÐÔÚ±í¸ñÖеÄλÖ㬿ÉÒÔÏÂÃæµÄ·½·¨È¡µÃÈ»ºóȥɾ³ý£º 
var row=document.getElementById("ÐеÄ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);
}
}

Õâ¶Î´úÂëҪɾ³ýÔ­À´µÄ±í¸ñµÄ±íÌ壬ÓÐÁ½¸öÎÊÌâ¡£Ê×ÏȲ»ÄÜÊÇdeleteRow(i)£¬Ó¦¸ÃÊÇdeleteRow(1)¡£ÒòΪÔÚɾ³ý±í¸ñÐеÄʱºò£¬±í¸ñµÄÐÐÊýÔڱ仯£¬Õâ¾ÍÊÇÎÊÌâµÄ¹Ø¼ü£¬rows.length×ÜÊÇÔÚ±äС£¬É¾³ýµÄÐÐÊý×ÜÊÇ»á±ÈÔ¤ÏëµÄÒªÉÙÒ»°ë£¬ËùÒÔÕýÈ·µÄɾ³ý±í¸ñµÄÐеĴúÂëÓ¦¸ÃÕâÑù£º  
function clearRow(){
objTable= document.getElementById("myTable");
var length= objTable.rows.length ;
for( var i=1; i<length; i++ )
{
objTable.deleteRow(1);
}
}
3¡¢¶¯Ì¬ÉèÖõ¥Ôª¸ñÓëÐеÄÊôÐÔ
A¡¢²ÉÓÃsetAttribute()·½·¨£¬¸ñʽÈçÏ£ºsetAttribute(ÊôÐÔ£¬ÊôÐÔÖµ)
˵Ã÷£ºÕâ¸ö·½·¨¼¸ºõËùÓеÄDOM¶ÔÏ󶼿ÉÒÔʹÓ㬵ÚÒ»¸ö²ÎÊýÊÇÊôÐÔµÄÃû³Æ£¬±ÈÈç˵£ºborder£¬µÚ¶þ¸ö¾ÍÊÇÄãҪΪborderÉèÖõÄÖµÁË£¬±ÈÈ磺1 
 var objMyTable = document


Ïà¹ØÎĵµ£º

107ÌõJavascriptµÄ³£ÓÃÓï¾ä

1.         document.write( " "); Êä³öÓï¾ä
2.JSÖеÄ×¢ÊÍΪ//
3.´«Í³µÄHTMLÎĵµË³ÐòÊÇ:document- >html- >(head,body)
4.Ò»¸öä¯ÀÀÆ÷´°¿ÚÖеÄDOM˳ÐòÊÇ:window- >(navigator,screen,history,location,document)
5.µÃµ½±íµ¥ÖÐÔªËصÄÃû³ÆºÍÖµ:document.getElementById( "±íµ¥ ......

JavascriptÖÐÀàµÄ¶¨ÒåºÍ¼Ì³Ð

ÀàµÄ¶¨ÒåÓÐ3ÖÖ»ù±¾·½·¨:
1¡¢´´½¨²¢ÄÜ·µ»ØÌض¨ÀàÐ͵ĶÔÏóµÄº¯Êý(¹¤³§º¯Êý)È磺
function wu()
{
  var w=new object;
  o.a=1;
  return o;
}ÓÃÕâÖÖ·½Ê½´´½¨¶ÔÏó£ºvar u=wu();
2¡¢´´½¨¹¹Ô캯Êý£¬ÓÃnewʵÀý»¯ÀýÈ磺
function wu()
{this.a=1;}
ÓÃÕâÖÖ·½Ê½´´½¨¶ÔÏó: var u=new wu();
3¡¢Ô­ÐÍ·½Ê½,À ......

JavaScript document¶ÔÏó

¶ÔÏóÊôÐÔ:
document.title                 //ÉèÖÃÎĵµ±êÌâµÈ¼ÛÓÚHTMLµÄ<title>±êÇ©
document.bgColor               //ÉèÖÃÒ³Ãæ±³¾°É«
document.fgCol ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ