-4
我想有一些超鏈接圖像,在一段時間後不斷變化..我使用了2個數組圖像和鏈接.. 2個相應的功能分別在2秒後執行更改圖像和鏈接。但是,我得到一個空白屏幕output..I寫的代碼爲:圖像交換超鏈接
<html>
<head>
<title> New Document </title>
</head>
<body>
<img id="img" width="1300" height="200"/>
<link id="link" >
<script type="text/javascript">
var x=0;
var y=0;
var images = new Array();
var links = new Array();
images[0] = "D:\images\31.jpg";
images[1] = "D:\images\32.jpg";
links[0] = "https://www.google.co.in" ;
links[1] = "https://www.facebook.com" ;
function changeImage()
{
document.getElementById("img").src=images[x];
x = (x + 1) % images.length;
}
function changeLinks()
{
document.getElementById("link").href=links[y];
y = (y + 1) % links.length;
}
window.onload = function() {
changeImage();
setInterval(changeImage,2000);
}
window.onload = function() {
changeLinks();
setInterval(changeLinks,2000);
}
</script>
</body>
</html>
可以üplz闡述..什麼是在你的代碼行中的文件?..和在哪裏給「\\」? – user2335676 2013-04-30 11:59:12
查看更多關於在Javascript中轉義字符的內容:http://www.w3schools.com/js/js_obj_string.asp JS中的基本字符串轉義! – Liv 2013-04-30 12:00:36
更好地複製/移動圖像到服務器路徑並使用像'../ images/31.jpg'這樣的相對路徑。使用文件url並指向磁盤並不是最佳選擇。 – Appleshell 2013-04-30 12:01:36