我在 gridview 中使用文本框,它的 onkeyup 功能似乎不起作用......
这是我的 GridView
<asp:TemplateField>
<HeaderStyle Width="12%" />
<HeaderTemplate>
Advance Detucted
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="TxtAdvanceDeducted" runat="server"
CssClass="text_box_height_14_width_50" onkeyup="check('this');"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="12%" HorizontalAlign="Center" />
</asp:TemplateField>
还有我的 javascript 函数,
var table = el.parentNode.parentNode.parentNode;
for (var y = 0; y < table.rows.length; y++)
{
for (var x = 0; x < table.rows[y].cells.length; x++)
{
if (table.rows[y].cells[x] == el)
{
alert("Row:" + y + " Cell: " + x);
}
}
}
当通过 webdeveloper 工具栏检查时,我收到错误,
el.parentNode 未定义
任何建议...
alert(table.rows.length)
给了我 3...但我有 2 行 + 一个标题行...
最佳答案
替换
onkeyup="check('this');" // you are passing a string 'this' to the function.
与
onkeyup="check(this);" // you are passing a reference of the element.
关于javascript - Javascript 中的parentNode 似乎不适合我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2332749/