[英]JQuery hide\show if checkbox is checked
我想制作一個表格,其中是否隱藏\\顯示行,具體取決於是否選中了標題中的復選框。 我的劇本:
<script contextmenu="text/javascript">
$(document).ready(function () {
$("#ShowPersonalDataList").change(function () {
if($(this).is("checked")){
$(".PersonalDataInset").Show;
return
} else
$(".PersonalDataInset").hide;
});
});
我的HTML:
<div id="CheckBoxTables">
<table class="CBTable">
<tr>
<th>
@Html.LabelFor(m => m.ColumnsNeeded.PersonalDataPartBool)
@Html.CheckBoxFor(m => m.ColumnsNeeded.PersonalDataPartBool, new { id = "ShowPersonalDataList" })
</th>
</tr>
<tr>
<td class="PersonalDataInset">
@Html.LabelFor(m => m.ColumnsNeeded.FirstNameBool)
@Html.CheckBoxFor(m => m.ColumnsNeeded.FirstNameBool)
</td>
</tr>
<tr>
<td class="PersonalDataInset">
@Html.LabelFor(m => m.ColumnsNeeded.LastNameBool)
@Html.CheckBoxFor(m => m.ColumnsNeeded.LastNameBool)
</td>
</tr>
<tr>
<td class="PersonalDataInset">
@Html.LabelFor(m => m.ColumnsNeeded.AppointmentBool)
@Html.CheckBoxFor(m => m.ColumnsNeeded.AppointmentBool)
</td>
</tr>
<tr>
<td class="PersonalDataInset">
@Html.LabelFor(m => m.ColumnsNeeded.DivisionBool)
@Html.CheckBoxFor(m => m.ColumnsNeeded.DivisionBool)
</td>
</tr>
</table>
</div>
我嘗試過以下解決方案:
但不幸的是,它們對我不起作用,我不知道為什么。
您使用錯誤的選擇器將元素狀態標識為已選中/未選中。 您可以使用this.checked
獲取檢查狀態並將其用作.toggle()
參數:
$("#ShowPersonalDataList").change(function () {
$(".PersonalDataInset").toggle(this.checked);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.