2010-02-25 32 views
0

工作,我用一个文本框,一个gridview内,其功能的onkeyup似乎没有工作....parentNode在Javascript中似乎并没有为我

这里是我的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行+一个标题行...

回答

2

更换

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

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

@rahul它的工作,但我不能接收警报... – 2010-02-25 09:12:11

+0

加上第一和第二里面的一些警报循环以及检查 – 2010-02-25 09:41:09

0

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

onkeyup =“check(this)

虽然这可能归结为asp语法。测试的一个好方法是alert或在firebug中使用console.log来查找传递给该函数的内容,例如

console.log(el); 

alert(el); 

的功能

0

的第一行,我不熟悉ASP:此要求各地引号?

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

问候,
斯泰恩

+0

@TheStijin看到我编辑的问题 – 2010-02-25 09:49:52