亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

現在要求點擊刪除鍵時,刪除當前這一行,不知道代碼問題出在哪里,求大神指導

現在要求點擊刪除鍵時,刪除當前這一行,不知道代碼問題出在哪里,求大神指導

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 關注
  • 1648 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號