简体   繁体   English

有替代innerHTML的方法吗? -黑莓浏览器上的问题

[英]Is there an alternative to innerHTML? - issue on Blackberry browser

Is there an alternative to innerHTML? 有替代innerHTML的方法吗? - issue on Blackberry browser -黑莓浏览器上的问题

Blackberry 4.6 browser does not seem to use innerHTML properly. Blackberry 4.6浏览器似乎无法正确使用innerHTML。 Instead of replacing contents, it appends contents! 而不是替换内容,而是附加内容!

function load_activities(){
    x$('#dummy').xhr('program.php',{
    method:'post', 
    data:   'action=list'.              
    callback: function(){
            document.getElementById("status2").innerHTML = this.responseText;
        }       
    });

How about cloning the node without children and then adding the new content? 克隆没有子节点的节点然后添加新内容怎么样?

callback: function () {
    var status2 = document.getElementById("status2");
    var copy = status2.cloneNode(false); // false indicates to not copy children
    copy.innerHTML = this.responseText;
    if (status2.nextSibling) {  // put the copy in the same place as the existing node
        var refchild = status2.nextSibling;
        status2.parentNode.removeChild(status2);
        refchild.parentNode.insertBefore(copy, refchild);
    }
    else { // existing node is the last child, copy can be appended to the end of the list
        var parent = status2.parentNode;
        parent.removeChild(status2);
        parent.appendChild(copy);
    }
}    

I have no way to test this, so I don't know for sure that cloneNode will work as expected and only copy the tags and attributes. 我没有办法对此进行测试,所以我不知道cloneNode是否会按预期工作,只复制标签和属性。 Hope it helps. 希望能帮助到你。

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

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