簡體   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