我想将此添加到我的html中,但它不起作用。
var html = '<div id="youkuplayer"></div>'
+'<script type="text/javascript" src="http://player.youku.com/jsapi">'
+'player = new YKU.Player("youkuplayer",{'
+'client_id: "81dab93633c39ff0",'
+'vid: "XNjQ4Nzk5MTA0_ev_1",'
+'width: "240",'
+'height: "200",'
+'autoplay: false,'
+'show_related: false'
+'});'
+'</script>';
。$( “#added_video”)的CSS( “显示”, “块”)附加(HTML);
但如果我使用静态html包含这个,它就可以了。
答案 0 :(得分:0)
您的代码中存在一些错误,您需要在代码中添加'</script><script>'
,如下所示:
var html = '<div id="youkuplayer"></div>'
+'<script type="text/javascript" src="http://player.youku.com/jsapi"></script><script>'
+'player = new YKU.Player("youkuplayer",{'
+'client_id: "81dab93633c39ff0",'
+'vid: "XNjQ4Nzk5MTA0_ev_1",'
+'width: "240",'
+'height: "200",'
+'autoplay: false,'
+'show_related: false'
+'});'
+'</script>';
答案 1 :(得分:0)
您的问题是SCRIPT标记,jQuery会阻塞它。
有关可能的解决方案,请参阅此答案:How to dynamically insert a <script> tag via jQuery after page load?