简体   繁体   English

Firefox的innerHTML替代

[英]innerHTML alternative for firefox

I am filling html table with following line of code 我用以下代码行填充html表

Javascript: Javascript:

var newTR = document.createElement("TR");
var newTD;

    newTD = document.createElement("TD");
    newTD.width = "22%"

    newTD.innerHTML = "<input type='text' name='AppOrderTxt1' readOnly='true'"+  
     "' id='AppOrderTxt' value=' test'  class='text-noborders' onFocus='this.blur()' size='3'/>";

    newTR.appendChild(newTD);

    if(document.all){
        tblRCRPCombo.children[0].appendChild(newTR);
    }else{

       tblRCRPCombo.insertRow(tblRCRPCombo.rows.length);                           
       tblRCRPCombo.rows[tblRCRPCombo.rows.length-1].innerHTML=newTR.innerHTML;
    }

When i am trying to get the request parameter value by name AppOrderTxt1 , it returns null in FireFox, while same thing is working in IE. 当我尝试通过名称AppOrderTxt1获取请求参数值时,它在FireFox中返回null ,而在IE中也是如此。

Might not be a problem but you have an extra ' in there: 可能不会有问题,但是里面有一个额外的'

newTD.innerHTML = "<input type='text' name='AppOrderTxt1' readOnly='true'"+  
     " id='AppOrderTxt' value=' test'  class='text-noborders' onFocus='this.blur()' size='3'/>";  

Also, the first if statement is working in firefox, but firefox won't enter that because of (document.all). 另外,第一个if语句在firefox中有效,但是由于(document.all),firefox不会输入该语句。 If you only have this row... 如果您只有这一行...

tblRCRPCombo.children[0].appendChild(newTR);

...instead of the whole if else statement, then it will work in FF and IE. ...而不是整个if语句,它将在FF和IE中运行。

Here's why: https://developer.mozilla.org/en/Mozilla_Web_Developer_FAQ 原因如下: https : //developer.mozilla.org/en/Mozilla_Web_Developer_FAQ

Some proprietary document objects such as document.all and document.layers are not part of the W3C DOM and are not supported in Mozilla. 一些专有的文档对象(例如document.all和document.layers)不是W3C DOM的一部分,并且在Mozilla中不受支持。 (There is partial undetectable support for document.all, though, in newer versions of Mozilla. However, that functionality only exists for compatibility with sites authored specifically for IE. You should not rely on Mozilla's document.all support on new pages.) The method document.getElementById() can be used instead. (不过,在较新版本的Mozilla中,对document.all的支持存在部分无法检测的功能。但是,该功能仅是为了与专门为IE创建的网站兼容。您不应该依赖Mozilla的document.all对新页面的支持。)可以改用document.getElementById()方法。

textContent替换innerHTML

tblRCRPCombo.rows[tblRCRPCombo.rows.length-1].textContent = newTR.textContent;

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

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