所以我尝试: 1)通过单击按钮切换背景颜色和 DIV 元素 2)通过单击按钮更改图像源(不是切换)。
代码对我来说非常简单,而且我认为它没有问题,但由于某种原因它不起作用!请帮助...任何建议将不胜感激队友。
<!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>