childNodes not working in Firefox and Chrome but working in IE

前端 未结 8 1942
太阳男子
太阳男子 2021-01-06 07:41

I have a gridview in its 3rd cell, there is textbox control, I am calling javascript function on onchange.

Can some body tell me why this is not working in Firefox a

相关标签:
8条回答
  • 2021-01-06 08:22

    Ishwar's answer of changing childNodes to children worked for me.

    0 讨论(0)
  • 2021-01-06 08:22

    As ChaosPandion says, IE ignores white-space text-nodes. The following should work cross-browser:

    var cell = grd.rows[rowindex].cells[3];
    for (var textbox=cell.firstChild; textbox.nodeType!==1; textbox=textbox.nextSibling);
    alert(textbox.value);
    

    However, you say you are calling the function on onchange. Presumably that means the onchange event for the textbox in question. In that case the event argument in your event handler should have a pointer to the textbox. Look at the target or srcElement property. e.g.

    function onChange(e) {
     e = e || window.event;
     var textbox = e.target || e.srcElement;
     alert(textbox.value);
    }
    
    0 讨论(0)
提交回复
热议问题