繁体   English   中英

Javascript中的parentNode似乎对我不起作用

[英]parentNode in Javascript doesn't seem to work for me

我在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 is undefined

任何建议...

alert(table.rows.length)给了我3 ...但是我有2行+ 1个标题行...

更换

onkeyup="check('this');" // you are passing a string 'this' to the function.

onkeyup="check(this);" // you are passing a reference of the element.

这是作为字符串而不是对象传递的,也许应该是:

的onkeyup =“校验(这)

不过,这可能取决于asp语法。 测试警报的好方法是使用警报或在firebug中使用console.log找出传递给函数的内容,例如

console.log(el);

要么

alert(el);

作为函数的第一行

我不熟悉ASP:是需要解决这个引号?

check('this') => check(this)

问候,
斯泰恩

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM