0

在我的视频模板站点中,我想在单击 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>

至少应该有一个函数来执行任务。但是怎么做呢?

<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>

这是小提琴:http: //jsfiddle.net/k68Zp/389/

4

1 回答 1

1

您需要在 HQ 的点击时调用showVideo()。所以您需要在 showVideo() 函数上方添加以下代码:

$(document).ready(function(){  
    $("#player_hq_nq").click(function(){  
        showVideo();  
   });  
});
于 2013-07-08T10:25:04.257 回答