-1
我想創建一個網站,其中有多個選擇題,並在正確答案上單擊時顯示結果扭曲或錯誤。
我被代碼卡住了,它顯示了所有的元素,因爲我已經給所有類同名。無法用同一個類名顯示具體答案
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".img1").hide();
$(".show1").click(function(){
$(".img1").show();
});
});
</script>
<style>
#header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
#nav {
background-color:#eeeeee;
height:160px;
width:100px;
float:left;
padding:5px;
}
#section {
width:800px;
float:left;
padding:10px;
}
#footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
</head>
<body>
<div style="width:960px; height:80px; background-color:#3b5998">
<div id="header">
<h1>City Gallery</h1>
</div>
<div id="nav">
London<br>
Paris<br>
Tokyo
</div>
<div id="section">
<div>
<table style="width:100%">
<tr>
<td colspan="3"><p>A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train?</p></td>
</tr>
<tr>
<td><a href="#" class="show1" style="text-decoration:none"><strong>A.</strong> 120 </a> <a href="#" class="img1"><img src= "images/logo/correct.png" width="14" height="14" /></a> </td>
<td><a href="#" class="show1" style="text-decoration:none" ><strong><strong>B.</strong> 180
</a> <a href="#" class="img1"><img src= "images/logo/wrong.png" width="14" height="14" /></a> </td>
</tr>
<tr>
<td><a href="#" class="show1" style="text-decoration:none" ><strong>C.</strong> 324
</a> <a href="#" class="img1"><img src= "images/logo/wrong.png" width="14" height="14" /></a> </td>
<td><a href="#" id="show1" style="text-decoration:none" ><strong>D.</strong> 150
</a> <a href="#" class="img1"><img src= "images/logo/wrong.png" width="14" height="14" /></a> </td>
</tr>
</table>
<table style="width:100%">
<tr>
<td colspan="3"><p>A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train?</p></td>
</tr>
<tr>
<td>
<a href="#" id="show1" style="text-decoration:none"><strong>A.</strong> 120 </a> <a href="#" class="img1"><img src= "images/logo/correct.png" width="14" height="14"/></a> </td>
<td><a href="#" id="show1" style="text-decoration:none" ><strong><strong>B.</strong> 180
</a> <a href="#" class="img1"><img src= "images/logo/wrong.png" width="14" height="14" /></a> </td>
</tr>
<tr>
<td><a href="#" id="show1" style="text-decoration:none" ><strong>C.</strong> 324
</a> <a href="#" class="img1"><img src= "images/logo/wrong.png" width="14" height="14" /></a> </td>
<td><a href="#" id="show1" style="text-decoration:none" ><strong>D.</strong> 150
</a> <a href="#" class="img1"><img src= "images/logo/wrong.png" width="14" height="14" /></a> </td>
</tr>
</table>
</div>
`enter code here`</div>
<div id="footer">
你真的有問題嗎? –
您正在使用ID「#show1」_four_次。 ID必須是唯一的=僅在文檔中使用一次。改變...... – Johannes