切换复选框的点击问题
请找到下面的代码
$("#chkCopy").toggle(function () {
copyDetails();
},
function () {
emptyCopyDetails();
});
// functions which do not have any effect on the checkbox
function copyDetails() {
}
function emptyCopyDetails() {
}
问题是复选框未显示选中状态。
提前致谢
Please find the code below
$("#chkCopy").toggle(function () {
copyDetails();
},
function () {
emptyCopyDetails();
});
// functions which do not have any effect on the checkbox
function copyDetails() {
}
function emptyCopyDetails() {
}
The issue is that checkbox is not showing the checked state.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
.toggle()
会中断检查,因为.toggle()
实际上是.toggle()
com/jquery/jquery/blob/1.4.4/src/event.js#L987" rel="nofollow">在click
事件上调用e.preventDefault()
下面。我不建议采用这种方法,而是推荐这样的方法:这里是包含上述内容的演示的更新/工作版本方法。
The
.toggle()
interrupts the check, since.toggle()
actually callse.preventDefault()
on theclick
event underneath. Instead of that approach, I'd recommend something like this instead:Here's an updated/working version of your demo with the above approach.
使用更改而不是切换
use change instead of toggle
来自 文档:
因此,如果您希望选中和取消选中复选框,则不能使用
toggle()
。您可以使用click()
代替:From the documentation:
So you can't use
toggle()
if you want the check box to be checked and unchecked. You can useclick()
instead:看看这个答案,你会完成同样的事情
Jquery切换事件是弄乱复选框值
take a look at this answer you would accomplish the same thing
Jquery toggle event is messing with checkbox value