2016-03-21 15 views
-1

Herkese merhaba ben bir krom uzantısı yapmaya çalışıyorum ama ne yapacağımı gerçekten emin değilim! Bu benim kodum (oldukça uzun), simgeyi tıklatıp video içerdiğinde bir rastgeleleştirme yapmaya çalışıyorum ama baktığım gibi anlayamıyorum ama oldukça özel bir soru!Nasıl krom uzantısı için bir html video rastgele

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

Her türlü cevap için teşekkürler! senin koduyla yanlış ne

cevap

0

Hızlı listesi:

  • sizin if sözdizimi hatalı, sen Açma parantezi ihmal ediyoruz.
  • Koşullarınızda değerleri karşılaştırmıyorsunuz, bir değer ataıyorsunuz. = yerine == kullanmalısınız.
  • İşlev bloğu, işlev gövdesinde bulunmaz, bu nedenle işlev her çağrıldığında değil, yalnızca bir kez yürütülür.
  • cevap için <p id="demo"></p>
+0

teşekkür iç HTML değiştirmeye yerine javascript kodu, sadece düz HTML olup olmadığını içeriği! öyleyse sözdizimini nasıl değiştiririm. Ayrıca 3. mermi noktasındayken ne demek istediğinden emin değilim! – memed

+0

veya 4. madde işaretiniz de! – memed

İlgili konular