Jquery,如何获取复选框未选中事件和复选框值? [英] Jquery, How get checkbox unchecked event and checkbox value?
本文介绍了Jquery,如何获取复选框未选中事件和复选框值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在取消选中选中的复选框并在弹出窗口中显示未选中的值时使用 jQuery 获取 checkbox
值.我试过下面的代码,但它不起作用
I want to get checkbox
value using jQuery when to uncheck the checked checkbox and show that unchecked value in the popup. I've tried below code but it not work
$("#countries input:checkbox:not(:checked)").click(function(){
var val = $(this).val();
alert('uncheckd' + val);
});
有没有可能通过这种方式获得未经检查的值?
Is it possible to get unchecked value in this way?
推荐答案
您的选择器只会将事件附加到在开始时选择的元素上.您需要在值更改时确定检查未选中状态:
Your selector will only attach event to element which are selected in the beginning. You need to determine check unchecked state when value is changed:
$("#countries input:checkbox").change(function() {
var ischecked= $(this).is(':checked');
if(!ischecked)
alert('uncheckd ' + $(this).val());
});
这篇关于Jquery,如何获取复选框未选中事件和复选框值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文