输入类型复选框在引导模式内不起作用 [英] input type checkbox not working inside bootstrap modal

查看:74
本文介绍了输入类型复选框在引导模式内不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么bootstrap模式中的复选框不起作用?

Why is that checkbox inside the bootstrap modal not working?

我使用此代码使其正常工作但仍有问题

I use this code to make it working but still have a problem

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');

}); 

当我点击它时,如果未经检查或在检查时未取消选中,则不会显示检查?但如果我点击跨区域,则复选框被标记为选中或取消选中

when i click it there is no check appears when its unchecked or it is not uncheck when its check? but if i click the span area the checkbox is marked as check or uncheck

这里是我的小提琴

推荐答案

猜猜你试图克服引导模态 e.preventDefault()在点击事件中 - 这就是为什么它永远不会起作用。这两个事件似乎相互混淆了吗?

Guess you try to overcome bootstrap modals e.preventDefault() in click events - this is why it never works. Also the two events seems to obsulete each other?

请改为尝试:

$('.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();
});

分叉小提琴: http://jsfiddle.net/AurPX/

这篇关于输入类型复选框在引导模式内不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆