示例代碼:瞄準正確的行元素
<tr><td>first_button</td><td>second_button</td></tr>
<tr><td>first_button</td></tr>
<tr><td>first_button</td><td>second_button</td></tr>
<tr><td>first_button</td></tr>
<tr><td>first_button</td><td>second_button</td></tr>
function someFunc(i) {
// first button appears on every row
first_button[i].style.display="none"; // works
// second button appears randomly
second_button[i].style.display="none"; // doesn't work as intended
}
// someFunc(2) targets the third row's "first_button" but
// the last row's "second_button". I want to target the
// third row's buttons, not the third button of each type.
var i
與每一行遞增。我想定位第i行的按鈕而不是每種類型的第i個按鈕。什麼是最簡單的方法來做到這一點?
如何做'first_button'和'second_button'變量得到填充? – gilly3
是否只有一個'second_button'? – George
@ gilly3它們只是表格中的html元素。 –