Javascript 如何更改html5源代码标签并播放视频

Javascript 如何更改html5源代码标签并播放视频,javascript,html,html5-video,Javascript,Html,Html5 Video,在我的视频模板站点中,当我单击HQ时,我想更改视频的源标签,只有视频应该开始播放,而不需要单击播放按钮,并且链接的文本应该在相同的功能中更改为nq 遵循html代码 {{if hqnq == true }} //jquery template variable no importance <div class="toolbar" id="controls"> <div style="float:right">

在我的视频模板站点中,当我单击HQ时,我想更改视频的源标签,只有视频应该开始播放,而不需要单击播放按钮,并且链接的文本应该在相同的功能中更改为
nq

遵循html代码

{{if hqnq == true }}     //jquery template variable no importance
   <div class="toolbar" id="controls">
      <div style="float:right">         
          <a href="#" data-role="button" data-theme="a" data-mini="true" data-inline="true" id="player_hq_nq">HQ</a>
          // the text of the link should change when you are clicking
      </div>
      <div style="clear:both"></div>    
  </div>
{{/if}}


<div id="video_player">
<video autobuffer controls autoplay>
    <source src="http://www.tools4movies.com/Droid/Default/Inception.mp4" type="video/mp4" width="auto" height="auto" id="video" />
</video>
</div>
{{if hqnq==true}//jquery模板变量不重要
//单击时,链接的文本应更改
{{/if}
而且至少应该有一个执行任务的功能。但如何做到这一点呢

<script type="text/javascript">
var button = document.getElementById('player_hq_nq');

function showVideo() {
    if (button.title == "nq") {
        document.getElementById("video").setAttribute("src", "http://www.tools4movies.com/Droid/Default/Inception.mp4");
        document.getElementById("video").load();
        document.getElementById("video").play();
    } else {
        document.getElementById("video").setAttribute("src", "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");
        document.getElementById("video").load();
        document.getElementById("video").play();
        button.title = "nq";
    }
}
</script>

var button=document.getElementById('player_hq_nq');
函数showVideo(){
如果(按钮标题==“nq”){
document.getElementById(“视频”).setAttribute(“src”),“http://www.tools4movies.com/Droid/Default/Inception.mp4");
document.getElementById(“视频”).load();
document.getElementById(“视频”).play();
}否则{
document.getElementById(“视频”).setAttribute(“src”),“http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");
document.getElementById(“视频”).load();
document.getElementById(“视频”).play();
button.title=“nq”;
}
}

这里是小提琴:

你需要调用showVideo()onclick of HQ。因此,您需要在showVideo()函数上方添加以下代码:

$(document).ready(function(){  
    $("#player_hq_nq").click(function(){  
        showVideo();  
   });  
});

我将测试它:)并将其放入javascript标记中,或者?它总是向我显示thsi错误。。未捕获的TypeError:Object#没有方法“load”,您能帮我吗?从代码中删除以下代码行,然后尝试运行它。document.getElementById(“视频”).load();