1
所以,正如你所看到的我可以使用javascript來顯示/隱藏元素,但是當你點擊.png時,它會顯示文本,但不會隱藏其他元素的文本。我一直在翻閱這個腳本,谷歌搜索它,我不能拿出答案。我想我需要另一雙眼睛,所以如果有人看看這個,讓我知道是否有錯誤或者是否遺漏了一些代碼。Javascript顯示/隱藏元素,爲什麼這段代碼不工作?
<html>
<head>
<meta name = "viewport" content = "initial-scale = 1.0, user-scalable = no" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="NKit.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript">
function showStuff(id) {
document.getElementById(id).style.display = 'block';
}
function hideStuff(id) {
document.getElementById(id).style.display = 'none';
}
</script>
</head>
<body>
<div class="content">
<section class="left">
<p>
<a href="#" onclick="showStuff('character1');" onclick="hideStuff('character2');"><img src="character1.png" id="char1" /></a>
</p>
<p>
<a href="#" onclick="showStuff('character2');" onclick="hideStuff('character1');"><img src="character2.png" id="char2" /></a>
</p>
</section>
<section class="right">
<span id="character1" style="display: none;">Show character1 information</span>
<span id="character2" style="display: none;">Character 2 information</span>
</section>
</div>
</body>
</html>
爲什麼在每個錨中有兩次「onClick」? – 2012-03-31 21:36:37