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(i);
}
}
3¡¢¶¯Ì¬ÉèÖõ¥Ôª¸ñÓëÐеÄÊôÐÔ
A¡¢²ÉÓÃsetAttribute(
Ïà¹ØÎĵµ£º
javascript³õѧÕß
——È«Ãæѧϰ¶ÔÏó¸ÅÄî
±¾ÎĽéÉÜÁ˼¸ºõËùÓйØÓÚ¶ÔÏóµÄ»ù±¾¸ÅÄʲôÊǶÔÏó£¬ÈçºÎ´´½¨¶ÔÏ󣬶ÔÏóµÄÊôÐÔµÄÉèÖúͶÁÈ¡£¬É¾³ýÊôÐԵķ½·¨£¬¹¹Ô캯Êý£¬¶ÔÏóÔÐÍ£¬¸¸À࣬×ÓÀ࣬¼Ì³ÐµÈµÈ¡£
1.¶ÔÏó
* ¶ÔÏóÊÇÒ»ÖÖ¸´ºÏÊý¾ÝÀàÐÍ£¬ËüÃǽ«¶à¸öÊý¾ÝÖµ¼¯ÖÐÔÚÒ»¸öµ¥ÔªÖУ¬¶øÇÒÔËÐÐʹÓÃÃû×ÖÀ´´æÈ¡ÕâЩֵ¡£½âÊ ......
ECMAScriptÖУ¬switchÓï¾ä¿ÉÒÔÓÃÓÚ×Ö·û´®£¬¶øÇÒÄÜÓò»Êdz£Á¿µÄֵ˵Ã÷Çé¿ö:
var BLUE="blue" , RED = "red" , GREEN = "green";
switch(sColor)
{
case BLUE: alert("Blue"); break;
&nb ......
deleteÖ»ÄÜɾ³ý¿ª·¢Õ߶¨ÒåµÄÊôÐÔ»ò·½·¨£¬ÔʼµÄECMAScript·½·¨²»ÄÜɾ³ý£¬ÒòΪ²»ÊÇ¿ª·¢Õ߶¨ÒåµÄ£¬±ÈÈ磺toString()¡£
var o = new Object;
o.name = "Nicholas";
delete o.name;
&n ......
¶¨ÒåºÍÓ÷¨
prompt() ·½·¨ÓÃÓÚÏÔʾ¿ÉÌáʾÓû§½øÐÐÊäÈëµÄ¶Ô»°¿ò¡£
Óï·¨
prompt(text,defaultText)
²ÎÊýÃèÊö
text
¿ÉÑ¡¡£ÒªÔÚ¶Ô»°¿òÖÐÏÔʾµÄ´¿Îı¾£¨¶ø²»ÊÇ HTML ¸ñʽµÄÎı¾£©¡£
defaultText
¿ÉÑ¡¡£Ä¬ÈϵÄÊäÈëÎı¾¡£
˵Ã÷
Èç¹ûÓû§µ¥»÷Ìáʾ¿òµÄÈ¡Ïû°´Å¥£¬Ôò·µ»Ø null¡£Èç¹ûÓû§µ¥»÷È·ÈÏ°´Å¥£¬Ôò·µ»ØÊäÈë×ֶε±Ç°Ï ......