2016-03-21 168 views
-1

大家好,我正在嘗試擴展Chrome擴展,但我不確定該怎麼做!這是我的代碼(這是相當長的)我試圖做一個隨機化,當你點擊圖標,並有視頻,但我不能理解它,因爲我查了它,但是一個相當具體的問題!我如何在html中擴展視頻以擴展Chrome擴展

<html> 

<head> 
<style type="text/css"> 
body { 
margin: 0px; 
padding: opx; 
font-family: Comic Sans MS; 
font-size: 13px; 
} 

</style> 
</head> 
</body> 

<body> 


<button onclick="myFunction()">Try again</button> 

<p id="demo"></p> 

<script> 
function myFunction() { 
    var x = Math.floor((Math.random() * 6) + 1); 
    document.getElementById("demo").innerHTML = x; 
} 

if x = 1) { 
    <video width="320" height="240" controls> 
    <source src="Clip 1.mp4" type="video/mp4"> 
    <source src="Clip 1.ogg" type="video/ogg"> 
Your browser does not support the video tag. 
</video> 
} 

if x = 2) { 
    <video width="320" height="240" controls> 
    <source src="Clip 2.mp4" type="video/mp4"> 
    <source src="Clip 2.ogg" type="video/ogg"> 
Your browser does not support the video tag. 
</video> 
} 

if x = 3) { 
    <video width="320" height="240" controls> 
    <source src="Clip 3.mp4" type="video/mp4"> 
    <source src="Clip 3.ogg" type="video/ogg"> 
Your browser does not support the video tag. 
</video> 
} 

if x = 4) { 
    <video width="320" height="240" controls> 
    <source src="Clip 4.mp4" type="video/mp4"> 
    <source src="Clip 4.ogg" type="video/ogg"> 
Your browser does not support the video tag. 
</video> 
} 

if x = 5) { 
    <video width="320" height="240" controls> 
    <source src="Clip 5.mp4" type="video/mp4"> 
    <source src="Clip 5.ogg" type="video/ogg"> 
Your browser does not support the video tag. 
</video> 
} 

if x = 6) { 
    <video width="320" height="240" controls> 
    <source src="Clip 6.mp4" type="video/mp4"> 
    <source src="Clip 6.ogg" type="video/ogg"> 
Your browser does not support the video tag. 
</video> 
} 
</script> 

</body> 
</html> 

感謝您的回覆!

回答

0

快速的什麼是你的代碼錯誤列表:

  • if的語法不正確,你省略左括號。
  • 如果條件不匹配,則您正在分配一個值。您應該使用==而不是=
  • 條件塊不包含在函數體中,所以它只會被執行一次,而不是每次調用該函數。
  • 您的內容,如果只是普通的HTML,而不是JavaScript代碼來修改<p id="demo"></p>
+0

感謝您的答覆內HTML!所以如何改變if語法。另外我不確定你的意思是你的第三點要點! – memed

+0

或您的第四個要點! – memed