无法更改视频属性.如何修复它



我正在一个菜单上工作,以改变我的videojs源,它部分工作。我可以改变我的视频源与$video_obj.src,但我无法改变我的标签,如nonHD甚至类样式.vjs-poster

我忘了什么吗?

$("ul.dl-menu a").click(function() {
	
	var $myClass 		=  $(this).attr("class");
	var $target         =  $(this).attr("id");
    var $content_path   = "~path~/media-video/";
	var $thumbs         = "~path~/media-video/thumbs/";
    if ($myClass === "library") {
	    var $vid_obj        = videojs("div_video");
	    var $video_div			= "div_video";
    }
    else {
	    var $vid_obj        = videojs("div_video_awards");
	    var $video_div			= "div_video_awards";
    }
	
      $vid_obj.ready(function() {
      $($video_div+'.poster').hide();
      $($video_div+'_html5_api').hide();
      $vid_obj.pause();
      $($video_div+'video source:nth-child(1)').attr("src",$content_path+'mp4/'+$target+'.mp4');
	  $vid_obj.src({ type: "video/mp4", src: $content_path+'mp4/'+$target+'.mp4' });
      $($video_div+'video').attr("src",$content_path+'mp4/'+$target+'.mp4');
	  $($video_div).attr("nonHD",$content_path+'mp4/'+$target+'.mp4');
      $($video_div).attr("HD",$content_path+'mp4-720p/'+$target+'.mp4');
      $($video_div+'video').attr("HD",$content_path+'mp4-720p/'+$target+'.mp4');
      $($video_div+'video').attr("nonHD",$content_path+'mp4/'+$target+'.mp4');
      $($video_div+'.vjs-poster').attr("style", 'background-image: url('+$thumbs+$target+'.jpg);');
      $($video_div+'.vjs-tech').attr("poster",$thumbs+$target+".jpg").show();
      $($video_div).attr('poster',$thumbs+$target+'.jpg');
      $($video_div).removeClass('vjs-playing').addClass('vjs-paused');
      var css = document.createElement("style");
	  css.type = "text/css";
      css.innerHTML = ".vjs-control.vjs-HD-button { color: silver; font-weight:normal; text-shadow: 0 0 5em #fff;}";
      document.body.appendChild(css);
      HD1 = false;
      $vid_obj.load();
      $($video_div+'_html5_api').show();
      setTimeout(function(){
      $vid_obj.play();
      }, 0);
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<video id="div_video" class="video-js vjs-sublime-skin vjs-big-play-centered" width="auto" height="auto" poster="http://video-js.zencoder.com/oceans-clip.png" HD="http://video-js.zencoder.com/oceans-clip.mp4" nonHD="http://video-js.zencoder.com/oceans-clip.mp4" controls>
<source src="http://video-js.zencoder.com/oceans-clip.mp4" type="video/mp4">
</video>
<div id="dl-menu" class="dl-menuwrapper">
  <button class="dl-trigger">Menu</button>
  <ul class="dl-menu">
    <li><a class="library" href="javascript:;" id="MBHD0790-03">Into the Woods</a></li>
    <li><a class="library" href="javascript:;" id="MBHD0790-04">Kingsman</a></li>
  </ul>
</div>

既然这样:

 $($video_div+'video').attr("nonHD",$content_path+'mp4/'+$target+'.mp4');

你会做

 $('video_divvideo').attr(....);

没有#,所以javascript将在dom中寻找像<video_divvideo>这样的标签,当然这是不存在的。

也许你想要

 $('#' +$video_div).attr(...);

?

相关内容

最新更新