Can't append [removed] element

后端 未结 18 2190
被撕碎了的回忆
被撕碎了的回忆 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:50

    I've seen issues where some browsers don't respect some changes when you do them directly (by which I mean creating the HTML from text like you're trying with the script tag), but when you do them with built-in commands things go better. Try this:

    var script = document.createElement( 'script' );
    script.type = 'text/javascript';
    script.src = url;
    $("#someElement").append( script );
    

    From: JSON for jQuery

提交回复
热议问题