2013-07-08 47 views
0

在我的視頻模板網站中,當我點擊總部時,我想更改視頻的源標記,只有視頻應該開始播放,而不點擊播放按鈕,並且該鏈接的文本應在相同的功能中更改爲nq如何更改html5源標記並播放視頻

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

回答

1

你需要調用showVideo()的onclick總部。所以你需要在showVideo()函數之上添加以下代碼:

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

我會測試它:)並且我把JavaScript標籤放在裏面嗎? –

+0

它顯示我總是thsi錯誤.. 未捕獲TypeError:對象#沒有方法'加載' 你能幫助我嗎? –

+0

從您的代碼中刪除以下代碼行,然後嘗試運行它。的document.getElementById( 「視頻」)的負載(); –