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

时间:2017-01-19 09:06:50

标签: javascript

我有这个代码而且这不起作用

<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>

这不起作用

1 个答案:

答案 0 :(得分:4)

ESCAPE&#34; /&#34;关闭标签

<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>