2014-07-20 83 views
0

當用戶在其鍵盤上單擊時,我正嘗試將腳本src =「jsmovermap1.js」更改爲腳本src =「jsmovermap2.js」。當你查看頁面元素時,我似乎有這個工作,但是頁面沒有更新到js源代碼。你有什麼建議來解決這個問題?在按鍵上更改腳本源

非常感謝!

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>Ireland Map</title> 
</head> 
<body> 
<div id="map"> 
</div> 

<script src="jquery-2.1.1.min.js"></script> 
<script src="raphael-min.js"></script> 
<script src="jsmovermap1.js" id="s1"></script> 

<script> 
x=1; 
alert(x); 
document.addEventListener('keydown', function (evt) { 
if (evt.keyCode === 38) { 
alert('The "UP" key is being held down...?'); 
x=x+1; 
alert(x); 
s1.src="jsmovermap"+(x)+".js" 
//s1.src = s1.src.replace("jsmovermap1.js","jsmovermap"+(x)+".js"); 

} 
if (evt.keyCode === 40) { 
alert('The "DOWN" key is being held down...?'); 
x=x-1; 
if(x<0){ 
x=0} 
alert(x); 
} 

}); 

</script> 
</body> 
</html> 
+0

嘗試'的document.getElementById(」 s1「)。src =」new src here「;'。 –

+0

試過這個男人,仍然沒有看到它:-( – owlwink

+0

嘗試加載一個新的腳本標籤,然後而不是改變現有的標籤 –

回答