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

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

rowIndex的問題

rowIndex的問題

qq_甘蔗_0 2015-11-23 21:18:57
<!DOCTYPE html><html><head><title>test</title>? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/><script type="text/javascript">function deleteRow(r)? {? var i=r.parentNode.parentNode.rowIndex;? document.getElementById('myTable').deleteRow(i);? document.getElementById("in").value=i;? }</script></head><body><table id="myTable" border="1"><tr>? <td>Row 1</td>? <td><input type="button" value="刪除" onclick="deleteRow(this)"></td></tr><tr>? <td>Row 2</td>? <td><input type="button" value="刪除" onclick="deleteRow(this)"></td></tr><tr>? <td>Row 3</td>? <td><input type="button" value="刪除" onclick="deleteRow(this)"></td></tr></table><input type="text" id="in"></body></html>方法中var i=r.parentNode.parentNode.rowIndex;為什么i可以得到r對應行的序號,和rowIndex的實現機制有關么?r.parentNode.parentNode得到的是table節點,table節點的rowIndex得到的是什么?
查看完整描述

1 回答

已采納
?
李曉健

TA貢獻1036條經驗 獲得超461個贊

r.parentNode.parentNode 得到的是tr ?tr有一個屬性是 rowIndex

r.parentNode.parentNode.parentNode 得到的是tbody ?tbody沒有rowIndex屬性?

r.parentNode.parentNode.parentNode.parentNode 得到的是table ?table也沒有rowIndex屬性

沒有的屬性去取值就會得到?undefined

查看完整回答
反對 回復 2015-11-23
  • 1 回答
  • 0 關注
  • 2254 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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