开发者

Checkbox is unclickable inside div that has onclick listener

开发者 https://www.devze.com 2023-02-22 14:21 出处:网络
I开发者_StackOverflow中文版 have a checkbox inside a div that has an onclick javascript event attached to it.

I开发者_StackOverflow中文版 have a checkbox inside a div that has an onclick javascript event attached to it.

When I click on the checkbox, the onclick event is fired, instead of the checkbox being checked.

Any ideas on how to fix this behaviour?

Thanks


You can try to change your code (in the jsfiddle.net example) to something like this:

$(function() {
    $('#click').click(function(event) {
        var $target = $(event.target);
        if (!$target.is(':input')) {
            // div and contents, except inputs
            alert('click');
        } else {
            // div's content inputs
        }
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号