Can't append [removed] element

后端 未结 18 2227
被撕碎了的回忆
被撕碎了的回忆 2020-11-21 06:11

Any idea why the piece of code below does not add the script element to the DOM?

var code = \"\";
$(\"#someElement\").append(cod         


        
18条回答
  •  醉酒成梦
    2020-11-21 06:34

    Another way you can do it if you want to append code is using the document.createElement method but then using .innerHTML instead of .src.

    var script = document.createElement( 'script' );
    script.type = 'text/javascript';
    script.innerHTML = 'alert("Hey there... you just appended this script to the body");';
    $("body").append( script );
    

提交回复
热议问题