我有一系列类似于以下HTML代码的表格:
<table id="film"><tr>
<th class="1">//HEAD CONTENT 1//</th>
</tr>
<tr>
<td class="1">//BODY CONTENT 1//</td>
</tr></table>
<table id="film"><tr>
<th class="2">//HEAD CONTENT 2//</th>
</tr>
<tr>
<td class="2">//BODY CONTENT 2//</td>
</tr></table>
我希望在点击表头(<th>
)时,表格可以单独扩展。此外,表格应该开始处于未扩展状态。我使用以下jQuery脚本:
$(document).ready(function(){
$('#film td').hide();
});
$(document).ready(function(){
var n1 = 0;
$('#film th.1').click(function(){
if(n1 == 0){
$('#film td.1').show();
n1 = 1;
}else{
$('#film td.1').hide();
n1 = 0;}
});
var n2 = 0;
$('#film th.2').click(function(){
if(n2 == 0){
$('#film td.2').show();
n2 = 1;
}else{
$('#film td.2').hide();
n2 = 0;}
});
});
然而,当我执行时,只有顶部的表格能够显示/隐藏,而第二个表格不能。 有人能看出我错在哪里吗?