从 jQuery 添加链接时,youtube 对象模板不显示
我已将对象模板存储在变量中,然后通过 jQuery 添加视频链接。我这样做是因为最终链接将通过 ajax 添加到对象模板中。
但是,视频没有显示。我不确定我做错了什么。示例代码在这里运行: http://jsbin.com/axifil
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.7.1");
google.setOnLoadCallback(function() {
var obj_template = '<object width="260" height="140">' +
'<param name="movie" value=""></param>' +
'<param name="allowFullScreen" value="true"></param>' +
'<param name="allowscriptaccess" value="always"></param>' +
'<embed src="" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="260" height="140"></embed>' +
'</object>';
var flash_obj = obj_template;
var video = $('.video');
$(flash_obj).find('object param[name="movie"]').attr('value', 'https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded');
$(flash_obj).find('object embed').attr('src', 'https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded');
alert(flash_obj);
$('.video_content').html(flash_obj);
$('.test').html('this shows');
});
</script>
<div id="top_row_center" class="video">
<p class="video_content"></p>
<p class="test"></p>
</div>
I have stored an object template in a variable and then I'm adding the video links via jQuery. I'm doing this because eventually the links will be added into the object template via ajax.
However, the video does not show up. I'm not sure what I'm doing wrong. The sample code is in action here: http://jsbin.com/axifil
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.7.1");
google.setOnLoadCallback(function() {
var obj_template = '<object width="260" height="140">' +
'<param name="movie" value=""></param>' +
'<param name="allowFullScreen" value="true"></param>' +
'<param name="allowscriptaccess" value="always"></param>' +
'<embed src="" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="260" height="140"></embed>' +
'</object>';
var flash_obj = obj_template;
var video = $('.video');
$(flash_obj).find('object param[name="movie"]').attr('value', 'https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded');
$(flash_obj).find('object embed').attr('src', 'https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded');
alert(flash_obj);
$('.video_content').html(flash_obj);
$('.test').html('this shows');
});
</script>
<div id="top_row_center" class="video">
<p class="video_content"></p>
<p class="test"></p>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该首先将
object
添加到 divvideo_content
然后更改movie
和src
因为在更改文档中不存在的字符串之前;
http://jsfiddle.net/V2nJG/1/
you should first add
object
to divvideo_content
then changemovie
andsrc
because before you'r changing the string that does not exsite on document;
http://jsfiddle.net/V2nJG/1/