我正在尝试使用 jquery 显示/隐藏 html 内容......这是代码:
HTML:
<table width="1077" border="0" cellspacing="4" cellpadding="4">
<tr>
<td height="100%"> </td>
<td id="headerText">
<h2>enter details below</h2>
</td>
<td width="17" rowspan="3" valign="top" id="headerText"></td>
<td id="headerText">
<h2 id="section"> test data</h2>
</td>
</tr>
<tr>
<td width="1" height="100%"> </td>
<td width="531" id="bodyText">more information</td>
<td width="476" id="bodyText"></td>
</tr>
<tr>
<td height="150"> </td>
<td valign="top">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="7%" id="bodyText2">
<label for="zip2">
<input type="checkbox" name="check_medical2" id="check_medical2">
</label>
</td>
<td width="93%">
<label for="textfield3"></label>
<label for="people3" id="bodyText">section 1</label>
</td>
</tr>
<tr>
<td height="10" colspan="2" id="bodyText2"></td>
</tr>
<tr>
<td id="bodyText2">
<input type="checkbox" name="check_dental2" id="check_dental2">
</td>
<td id="bodyText">section 2</td>
</tr>
<tr>
<td height="10" colspan="2" id="bodyText5"></td>
</tr>
<tr>
<td id="bodyText2">
<input name="check_life_insurance2" type="checkbox" id="check_life_insurance2">
</td>
<td id="bodyText">section 3</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="30%"></td>
<td width="43%"> </td>
<td width="27%"> </td>
</tr>
</table>
<p> </p>
</td>
<td valign="top">
<br>
</td>
</tr>
</table><s:submit value="submit" name="submit" />
jQuery:
$('#check_life_insurance2').on("click", function () {
if ($('#check_life_insurance2').prop("checked")) {
$('#section').show();
} else {
$('#section').hide();
}
});
有人可以告诉我哪里出错了。
检查第3节时,检查了。应显示测试数据。但由于某种原因它失败了。
感谢您的帮助