更新时间:2023-12-04 23:34:22
您不必加载到你的DOM。
对于脚本标记,你可以只是做..
You need not "load" it into your DOM. For script tags, you could just do..
eval("<script>alert('Hi!');</script>");
更新:
如果您导致包含的两个 HTML和脚本的节点,请执行下列操作。
If you result contains both HTML and SCRIPT nodes, do the following..
$.each(nodes, function(i, node) { //result might contain muliple HTML/Script nodes
if (node.tagName == "SCRIPT") {
eval(node.innerHTML);
//Appending to DOM also executes the script. So we do eval() instead, which does the equivalent.
} else {
$(node).appendTo($('#returnData')); //And append your HTML nodes to the desired target div
}
});