2017-01-28 113 views
1

我需要此功能的全部功能,但我似乎忘了如何將多個JavaScript文件連接到一個功能。 這裏是我的index.html自定義HTML5 Mp3播放器

<!DOCTYPE html> 
<html> 
<head> 
<script type="text/javascript" 
source src="/storage/ 
emulated/0/Documents/ 
Mp3Player/js/ 
MyScript.js"></script> 
<script type="text/javascript" 
source src="/storage/ 
emulated/0/Documents/ 
Mp3Player/js/MyScript1.js"></ 
script> 
</head> 
<body> 
<img src="/storage/emulated/0/ 
Documents/Mp3Player/html/ 
images/play.jpg" width="200" 
height="200" onclick="play(); 
changeImage();"> 
<audio id="audio" src="/storage/ 
emulated/0/Documents/ 
Mp3Player/html/music/ 
Rap_In_Darkness.mp3 "/> 
</body> 
</html> 

這裏的MyScript.js的音頻播放。

function play(){ var myAudio = 
document.getElementById 
("audio"); if(myAudio.paused) 
myAudio.play(); else 
myAudio.pause(); } 

這裏是暫停/播放按鈕圖像的MyScript1.js。

function changeImage() { if 
(document.getElementById 
("imgClickAndChange").src == "/ 
storage/emulated/0/ 
Documents/Mp3Player/html/ 
images/Pause.jpg") { 
document.getElementById 
("imgClickAndChange").src = "/ 
storage/emulated/0/ 
Documents/Mp3Player/html/ 
images/play.jpg "; } else { 
document.getElementById 
("imgClickAndChange").src = " 
storage/emulated/0/ 
Documents/Mp3Player/html/ 
images/Pause.jpg "; } } 
+0

@MoinuddinQuadri能你解決這個問題我想知道你是否記得如何將多個.js文件鏈接到一個html,而不會造成混亂 –

回答

1

修改您的index.html這樣

<!DOCTYPE html> 
<head> 
<script type="text/javascript" 
src="/storage/ 
emulated/0/Documents/ 
Mp3Player/js/ 
MyScript.js"></script> 
<script type="text/javascript" 
src="/storage/ 
emulated/0/Documents/ 
Mp3Player/js/MyScript1.js"></ 
script> 
</head> 
<body> 
<img src="/storage/emulated/0/ 
Documents/Mp3Player/html/ 
images/play.jpg" width="200" 
height="200" onclick="play(); 
changeImage();"> 
<audio id="audio" src="/storage/ 
emulated/0/Documents/ 
Mp3Player/html/music/ 
Rap_In_Darkness.mp3 "/> 
</body> 
</html> 

然後你MyScript.js這樣

function play(){ var myAudio = 
document.getElementById 
("audio"); if(myAudio.paused) 
myAudio.play(); else 
myAudio.pause(); } 

最後,你MyScript1.js這樣

function changeImage() { if 
(document.getElementById 
("imgClickAndChange").src == "/ 
storage/emulated/0/ 
Documents/Mp3Player/html/ 
images/Pause.jpg") { 
document.getElementById 
("imgClickAndChange").src = "/ 
storage/emulated/0/ 
Documents/Mp3Player/html/ 
images/play.jpg "; } else { 
document.getElementById 
("imgClickAndChange").src = " 
storage/emulated/0/ 
Documents/Mp3Player/html/ 
images/Pause.jpg "; } } 
+0

我認爲這打破了我的代碼,但是我的意思是它不工作沒有進攻 –

+0

那麼,控制檯中的錯誤消息是什麼? @AnonymationTwentyFourSeven –

+0

排序沒有控制檯閱讀droidedit –