更新时间:2023-12-04 23:33:52
我累了,没有思考.您可以只使用本机 innerHTML
方法而不是 .html()
:
I'm tired and not thinking. You can just use the native innerHTML
method instead of .html()
:
$('#feedback-' + idfeedback)[0].innerHTML = x;
原答案:
Original answer:
我的直觉是您链接的答案对您不起作用,因为包含的脚本是使用 src
属性调用的,而不是 <script>
之间的脚本内容> 和 </script>
标签.这可能有效:
My hunch is that the answer you linked doesn't work for you because the included scripts are called with a src
attribute rather than script content between the <script>
and </script>
tags. This might work:
$.ajax({
url: 'example.html',
type: 'GET',
success: function(data) {
var dom = $(data);
dom.filter('script').each(function(){
if(this.src) {
var script = document.createElement('script'), i, attrName, attrValue, attrs = this.attributes;
for(i = 0; i < attrs.length; i++) {
attrName = attrs[i].name;
attrValue = attrs[i].value;
script[attrName] = attrValue;
}
document.body.appendChild(script);
} else {
$.globalEval(this.text || this.textContent || this.innerHTML || '');
}
});
$('#mydiv').html(dom.find('#something').html());
}
});
请注意,这尚未经过任何测试,可能会吃掉婴儿.
Note, this has not been tested for anything and may eat babies.