开发者

jQueryMobile Checkbox fires change event for entire controlgroup

开发者 https://www.devze.com 2023-03-10 05:25 出处:网络
I have a set of checkboxes setup in a series of div fieldcontain + fieldset controlgroups. They are grouped by topic with 12 main开发者_运维技巧 topics and 2-5 sub-topic under each.

I have a set of checkboxes setup in a series of div fieldcontain + fieldset controlgroups. They are grouped by topic with 12 main开发者_运维技巧 topics and 2-5 sub-topic under each.

When I "change" a checkbox, it fires the change event for the entire controlgroup. If I remove the control group fieldset, it fires the change event (when tapped) for the entire list, whether I use input[name="checkbox_name"] or input.checkbox-class.

How do I get the change for just the actual checkbox changed (from unchecked to checked or checked to unchecked)?


Assuming you're doing something like this:

$('input:checkbox').change(function ()
{
    // stuff
});

You can prevent the event from bubbling using event.stopPropagation():

$('input:checkbox').change(function (e)
{
    e.stopPropagation();
});

You can stop event bubbing and prevent other event handlers on the same element from running using event.stopImmediatePropagation().


Thanks @Matt Ball but I found this did what I needed:

$('input[name="subtopics_chosen"]:checked').live('change',function()

Before I had

$('input[name="subtopics_chosen"]').live('change',function()

I'll keep your StopPropagation tip for another day, though, I did not know about it.

0

精彩评论

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

关注公众号