2010-02-25 31 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