为什么 Bootstrap 模式中的复选框不起作用?
我使用这段代码使其工作但仍然有问题
documentBody.on('click','.checkInp',null,function(e) {
var checkbox = $(this).find(":checkbox"),
checked = checkbox.is(":checked");
checkbox.prop("checked", !checked);
});
documentBody.on('click','.checkInp :checkbox',null,function(e) {
$(this).parent('span').trigger('click');
});
当我点击它时,未选中时没有选中,或者选中时未选中?但如果我单击跨度区域,复选框将标记为选中或取消选中
这是我的 fiddle
最佳答案
我猜你试图克服点击事件中的 Bootstrap 模式 e.preventDefault()
- 这就是它永远不起作用的原因。这两个事件似乎也相互排斥?
试试这个:
$('.checkInp input:checkbox').on('click', function(e) {
// prevents the event from bubbling up the DOM tree
// eg the modal from cancelling the event
e.stopImmediatePropagation();
var checked = (e.currentTarget.checked) ? false : true;
e.currentTarget.checked=(checked) ? false : checked.toString();
});
fork fiddle :http://jsfiddle.net/AurPX/
关于javascript - 输入类型复选框在 Bootstrap 模式中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17696321/