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

发布于 2024-09-25 21:41:59 字数 387 浏览 3 评论 0原文

有没有innerHTML 的替代方案? - Blackberry 浏览器问题

Blackberry 4.6 浏览器似乎无法正确使用innerHTML。 它不是替换内容,而是附加内容!

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

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

Blackberry 4.6 browser does not seem to use innerHTML properly.
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;
        }       
    });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那支青花 2024-10-02 21:41:59

克隆没有子节点的节点然后添加新内容怎么样?

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);
    }
}    

我无法对此进行测试,因此我不确定 cloneNode 是否会按预期工作并且仅复制标签和属性。希望有帮助。

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. Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文