首先,对于这个模糊的问题感到抱歉,我不知道如何将其写成文字.我的问题最好通过一个例子说明.
我正在使用一个带有几个复选框的bootstrap下拉菜单.我使用了一些很好的FontAwesome图标来改变它们的外观.但是,当我尝试使用jQuery对这些复选框的状态执行某些操作时,第一次检查/取消选中似乎有效,但任何后续切换(检查/取消选中)都不起作用...
$('.js-inputhit').click(function() {
if (this === event.target) {
$(this).find(':input').click();
}
});
$('.js-inputhit :input').click(function(e) {
e.stopPropagation();
});
$('.selectchat_all').click(function() {
$('.selectchat_active').attr('checked', false);
$('#chat1, #chat2, #chat3, #chat4').attr('checked', true);
});
$('.selectchat_active').click(function() {
$('.selectchat_all').attr('checked', false);
$('#chat1, #chat2, #chat3, #chat4').attr('checked', false);
});Run Code Online (Sandbox Code Playgroud)
/*Adding custom checkbox icons*/
label {
position: relative;
padding-left: 20px;
cursor: pointer;
}
label:before,
label:after {
font-family: FontAwesome;
font-size: 14px;
/*absolutely positioned*/
position: absolute;
top: 0;
left: 0;
}
label:before {
content: '\f096';
/*unchecked*/
}
label:after {
content: '\f046';
/*checked*/
/*checked icon will …Run Code Online (Sandbox Code Playgroud)