我想在點擊文本時更改文本的顏色。任何人都可以讓我知道爲什麼這段代碼不起作用嗎?如何在點擊文本時更改文本的顏色
<html>
<body>
<center>
<div id="web" style="color:black" onclick="changeformat(this.id)"> Web </div>
<div id="img" style="color:blue" onclick="changeformat(this.id)"> Images </div>
<div id="news" style="color:blue" onclick="changeformat(this.id)"> News </div>
</center>
</body>
</html>
<script>
function changeformat(type)
{
document.getElementById('web').style = "color:blue;";
document.getElementById('img').style = "color:blue";
document.getElementById('news').style = "color:blue";
document.getElementById(type).style = "color:black";
}
</script>
@Derek:是的,我看到了它10秒爲時已晚:d – intelis 2013-03-28 04:07:45
http://jsfiddle.net/eUMDL/ – 2013-03-28 04:20:49