为了账号安全,请及时绑定邮箱和手机立即绑定

现在要求点击删除键时,删除当前这一行,不知道代码问题出在哪里,求大神指导

现在要求点击删除键时,删除当前这一行,不知道代码问题出在哪里,求大神指导

Echo_Chien 2016-08-05 16:21:54
<!doctype html><html><head><meta charset="utf-8"><title>无标题文档</title></head><body><p>请输入姓名:<input type="text" id="text">   请输入年龄:<input type="text" id="age">   <input type="button" value="添加" onclick="add()">   </p><script>          var text=document.getElementById("text");   var age=document.getElementById("age");   var table=document.createElement("table");           table.border=1;           table.width="800";   table.cellSpacing="0";   var tbody=document.createElement("tbody");   table.appendChild(tbody);   var ten=document.createTextNode("ID");   var tena=document.createTextNode("姓名");   var tenb=document.createTextNode("年龄");   var tenc=document.createTextNode("操作");      tbody.insertRow(0);   tbody.rows[0].insertCell(0);   tbody.rows[0].cells[0].appendChild(ten);   tbody.rows[0].insertCell(1);   tbody.rows[0].cells[1].appendChild(tena);   tbody.rows[0].insertCell(2);   tbody.rows[0].cells[2].appendChild(tenb);   tbody.rows[0].insertCell(3);   tbody.rows[0].cells[3].appendChild(tenc);   document.body.appendChild(table);   var i=1; function add(){        var j=0;   var ten=document.createTextNode(i);   var tena=document.createTextNode(text.value);   var tenb=document.createTextNode(age.value);   var tenc=document.createElement("input");       tenc.value="删除";   tenc.type="button";   tenc.onclick="del(this)";       tbody.insertRow(i);   tbody.rows[i].insertCell(j);   tbody.rows[i].cells[j].appendChild(ten);   tbody.rows[i].insertCell(j+1);   tbody.rows[i].cells[j+1].appendChild(tena);   tbody.rows[i].insertCell(j+2);   tbody.rows[i].cells[j+2].appendChild(tenb);   tbody.rows[i].insertCell(j+3);   tbody.rows[i].cells[j+3].appendChild(tenc);       i++;j++;   }    function del(obj){           var fix=obj.parentNode.parentNode.parentNode;   var ok=obj.parentNode.parentNode;       fix.removeChild(ok); if(tbody.length==1){i=0}     }  </script></body></html>
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1591 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信