日期:2014-05-16  浏览次数:20376 次

怎样用javascript删除用户选定的表格行?
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> Untitled   Document </title>
<script   language= "javascript ">
var   rowIndex   =   0;
function   AddOneLine(str1)  
{
var   row   =   userlist.insertRow(userlist.rows.length);

var   col   =   row.insertCell(0);
col.innerHTML   =   " <input   name= 'checkbox '   type= 'checkbox '   value= ' "+rowIndex+ " '   id= 'checkbox_ "+rowIndex+ " '   /> ";
col.setAttribute( "align ", "center ");
col   =   row.insertCell(1);
col.innerText   =   rowIndex;
col.setAttribute( "align ", "center ");


row.setAttribute( "id ",   "row "+rowIndex);  
row.setAttribute( "name ",   "row "+rowIndex);
rowIndex++;
}

//清空电话列表
function   clearlist(){
var   p=0;
var   ls_t=document.all( "userlist ");
while   (p <userlist.rows.length){
    if   (document.getElementById( "checkbox_ "+p).checked==true){
ls_t.deleteRow(p);
p=0;
}else{
p++;
}
}
}
</script>
</head>

<body>
<input   name= "add "   type= "button "       onclick= "AddOneLine( '未知 ') "   value= "add "/>
<input   name= "del "   type= "button "   value= "del "     onclick= "clearlist() "/>
<div   style= "overflow:auto;   width:100%;   height:220 ">
    <table   width= "750 "   border= "0 "   cellspacing= "0 "   cellpadding= "0 "   id= "userlist ">
    <th   width= "27 "> </th>
    <th   width= "102 "> </th>
    <th   width= "80 "> </th>
    <th   width= "67 "> </th>
    <th   width= "63 "> </th>
    <th   width= "85 "> </th>
    <th   width= "119 "> </th>
    <th> </th>
                            </table>
</div>
</body>
</html>

上面这个页面想要做成当用户选中表中的checkbox后,按del按钮会删除所有选中的数据行,可是为什么会出错呢?请高手讲讲。


------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content