[問題] 如何以JavaScript取得表格中某欄位的值

看板Web_Design作者 (I am the one...)時間19年前 (2006/06/04 17:46), 編輯推噓2(203)
留言5則, 2人參與, 最新討論串1/1
我的表格長得像這樣 <form name="form1"> <table border="1" width="100%" id="table1"> <tr> <th>編號</th><th>選取</th> </tr> <tr> <td>13579</td> <td> <button name="B3">Select 13579</button> </td> </tr> <tr> <td>24680</td> <td> <button name="B4">Select 24680</button> </td> </tr> <tr> <td>12345</td> <td> <button name="B5">Select 12345</button> </td> </tr> </table> </form> 我想要在按下任何row中的button OnClick時取得該row第一個column的值 請問這樣的JavaScript要怎麼寫呢? 謝謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.91.10

06/04 18:57, , 1F
document.getElementById("table1") 取得該table
06/04 18:57, 1F

06/04 18:58, , 2F
table.rows.length 可知道該table有幾筆row
06/04 18:58, 2F

06/04 19:00, , 3F
table.rows[i].cells.length 可知道該筆row有幾個td
06/04 19:00, 3F

06/04 19:01, , 4F
最後用innerText取得td內的文字
06/04 19:01, 4F

06/05 00:25, , 5F
感謝~
06/05 00:25, 5F
文章代碼(AID): #14Wglreb (Web_Design)
文章代碼(AID): #14Wglreb (Web_Design)