gpt4 book ai didi

javascript - 如何将 <script></script> 附加到
并执行它?

转载 作者:行者123 更新时间:2023-11-30 09:39:45 24 4
gpt4 key购买 nike

我有这段代码,但它不起作用

<script>
dialogFun();
function dialogFun(){

var code="<div style='font-size: 12px' id='dialog'><script src='https://content.jwplatform.com/libraries/xyz.js'> </script><div id='jwplyr'>Loading the player...</div><script type='text/javascript'>jwplayer('jwplyr').setup({'file': 'http://content.jwplatform.com/videos/xyz-lusPHdHK.mp4','image':'http://content.jwplatform.com/thumbs/xyz-320.jpg'});</script></div>";


console.log(code);
$( "body" ).append( code );
}
</script>

这是行不通的

最佳答案

转义结束标签的“/”

<script>
dialogFun();
function dialogFun(){

var code = "<div style='font-size: 12px' id='dialog'>"+
"<script src='https://content.jwplatform.com/libraries/xyz.js'><\/script>"+
"<div id='jwplyr'>Loading the player...</div>"+
"<script type='text/javascript'>jwplayer('jwplyr').setup({'file': 'http://content.jwplatform.com/videos/xyz-lusPHdHK.mp4','image':'http://content.jwplatform.com/thumbs/xyz-320.jpg'});<\/script><\/div>";


console.log(code);
$( "body" ).append( code );
}
</script>

关于javascript - 如何将 &lt;script&gt;&lt;/script&gt; 附加到 <div> 并执行它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41737728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com