从 jQuery 添加链接时,youtube 对象模板不显示

发布于 2025-01-06 11:10:19 字数 1565 浏览 2 评论 0原文

我已将对象模板存储在变量中,然后通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白云悠悠 2025-01-13 11:10:19

您应该首先将 object 添加到 div video_content 然后更改 moviesrc
因为在更改文档中不存在的字符串之前;

  $('.video_content').html(obj_template );
  var flash_obj = $('.video_content object');
  var video = $('.video');
  $(flash_obj).find('param[name="movie"]').attr('value', 'https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded');
  $(flash_obj).find('embed').attr('src', 'https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded');
  console.log(flash_obj);
  $('.test').html('this shows');

http://jsfiddle.net/V2nJG/1/

you should first add object to div video_content then change movie and src
because before you'r changing the string that does not exsite on document;

  $('.video_content').html(obj_template );
  var flash_obj = $('.video_content object');
  var video = $('.video');
  $(flash_obj).find('param[name="movie"]').attr('value', 'https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded');
  $(flash_obj).find('embed').attr('src', 'https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded');
  console.log(flash_obj);
  $('.test').html('this shows');

http://jsfiddle.net/V2nJG/1/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文