【问题标题】:youtube object template not showing when links added from jQuery从 jQuery 添加链接时,youtube 对象模板不显示
【发布时间】:2012-02-16 16:04:15
【问题描述】:

我已经在一个变量中存储了一个对象模板,然后我通过 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>

【问题讨论】:

    标签: jquery ajax flash youtube-api


    【解决方案1】:

    您应该首先将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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多