简体   繁体   English

jQuery .html功能剥离标签

[英]jquery .html feature stripping tags

I'm attempting to modify elements and give them elements. 我正在尝试修改元素并为其提供元素。 The Table and elements are all created. 表和元素均已创建。 However, upon attempting to load the s into the the response text strips the s. 但是,在尝试将s加载到响应中时,响应文本会将s剥离。 I've verified response text is propping by loading it on it's own page, however when using the below code. 我已经通过将响应文本加载到自己的页面上来验证响应文本是否正确,但是使用以下代码时。 The tags get stripped. 标签被剥离。

$("#Records").load("get.php?"+str, function(){
    $('.trclass').each(function(){
        var id=this.id;
        var xmlhttp=new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                $('#'+id).html(xmlhttp.responseText);
            }
        }
        xmlhttp.open("GET","get.php?Read=true&"+str2,false);
        xmlhttp.send();                      
    });
});

I've verified the responseText is correct. 我已经验证了responseText是正确的。 I'm fine with turning this into a .append() or a .load() just need something that works. 我可以将其转换为.append()或.load(),只需要一些有效的方法即可。 I've seen solutions involving making a new div and putting a table in that and sending that back but that's way too hacky and I don't want to do that on get.php. 我已经看到了一些解决方案,其中包括制作一个新的div并在其中放置一个表格并将其发送回去,但这太hacky了,我不想在get.php上这样做。 Looking for a good solution. 寻找一个好的解决方案。 Hopefully from this section of code. 希望从本节代码中。

Thanks 谢谢

I found the solution here jquery inserted HTML is rendered as a raw text 我在这里找到了解决方案, jQuery插入的HTML呈现为原始文本

I used the answer of $('div.desc').html($.parseHTML(unescape(that_string))); 我用了$('div.desc')。html($。parseHTML(unescape(that_string)));的答案;

And it worked perfectly. 而且效果很好。

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

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