gpt4 book ai didi

javascript - 获取 jQuery 处理复选框单击事件

转载 作者:行者123 更新时间:2023-11-28 21:09:30 26 4
gpt4 key购买 nike

我知道这个问题可能会因为重复而被关闭(抱歉,如果是的话),但在我的特殊情况下,功能无法按预期工作可能会出现不同的问题,然后是其他类似的问题。

假设我们有一个标记:

<div>
<label for="IsRecurring">Is Recurring</label>
</div>
<div>
<input id="IsRecurring" name="IsRecurring" type="checkbox" value="true">
<input name="IsRecurring" type="hidden" value="false" />
</div>

<div id="schedulerTypesList" style="display:none">
<div>
<label for="ScheduleTypeId">Schedule</label>
</div>
<div class="editor-field">
<input type="hidden" name="ScheduleTypeId" id="ScheduleTypeId" value="" />

<ul id="ScheduleTypeIdlist" >
<li>Once a weel</li>
</ul>
</div>
</div>

并在 document.ready 事件中附加一个 JS:

$(document).ready(function() {
$('#IsRecurring').click(function () {
var thisCheck = $(this);
if (thischeck.is(':checked'))
$('#schedulerTypesList').show();
}
else {
$('#schedulerTypesList').hide();
})
});

Demo in JSFiddle.

为什么复选框点击事件没有切换 div 的显示?

最佳答案

几个问题!!

$(document).ready(function() {
$('#IsRecurring').click(function() {
var thisCheck = $(this);
if (thisCheck.is(':checked')) { // added this closing bracket
$('#schedulerTypesList').show();
}
else {
$('#schedulerTypesList').hide();
} // added this closing bracket
});
});

ifthischeck 而不是 thisCheck 之后缺少括号,并添加了正确的右括号。工作演示:http://jsfiddle.net/manseuk/4DqXv/18/

关于javascript - 获取 jQuery 处理复选框单击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9036085/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com