javascript - Javascript 中的parentNode 似乎不适合我

标签 javascript gridview textbox onkeyup

我在 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/

相关文章:

android - 为什么我使用 StickyGridHeaders 库得到 NullPointerException,而其他人使用同一个库就好了?

c# - 如何通过更改同一 ListView 行中下拉列表的项目来更新文本框中的文本

php - 相似词如何匹配?

javascript - 如何从异步调用返回响应?

javascript - JQuery .load with Setinveral,在刷新时它会重置某些功能并禁用它们

javascript - TypeError : Cannot read property 'get' of undefined. 是 npm 的问题吗?

asp.net - 如何更改asp悬停时的背景图像:CommandField in a Gridview

asp.net - C#/ASP.Net - 提取 GridView 中列的位值

wpf - wpf中的字符串格式

css - 网站相对于视口(viewport)宽度的定位