所以我試圖: 1)通過點擊一個按鈕來切換背景顏色和DIV元素 2)通過點擊一個按鈕來改變圖像源(不切換)。用Jscript在HTML中切換圖像
代碼對我來說很簡單,對,我沒有看到它的問題,但由於某種原因只是不工作! 請幫助...任何建議將高度讚賞隊友。
<!Doctype HTML>
<HTML>
<head>
<script>
function changeimage()
{ x = document.getElementById("image");
x.src="e:\PHOTOS\garfield-coffee.jpg";
x.alt="e:-\PHOTOS\garfield-coffee.jpg"; // the new image doesnt load, but if I specify an "alt", it seems to work.
}
function changeDivColor()
{ x = document.getElementById("main_container")
if(x.style.backgroundColor=="#3B7AF0") // the if thens just dont work. Simply changing color one time does.
{ x.style.backgroundColor="#dfedf0"; }
else
{ x.style.backgroundColor=="#3B7AF0"; }
}
</script>
</head>
<body>
<div id="main_container" style="background-color:#3B7AF0;width:1800px;height:1800px;font-size:10pt">
<img id="image" src="e:\photos\garf2.jpg" width:40px height:40px></img>
<div id="Scriptarea"> <!-- Javascript stuff -->
<form>
<input type="button" onclick="changeimage()" value="click here to change garfield"></input>
<input type="button" onclick="changeDivColor()" value="Change DIV color"></input>
</form>
</div> <!-- Javascript stuff -->
</div>
</body>