开发者

jQuery UI MultiSelect Widget 1.8 click handler discrepancy

开发者 https://www.devze.com 2023-02-01 13:33 出处:网络
I have an instance of Eric Hynd\'s multiselect widget on my site. In it\'s click handler, I have an alert telling me how many checkboxes are selected-

I have an instance of Eric Hynd's multiselect widget on my site.

In it's click handler, I have an alert telling me how many checkboxes are selected-

alert($(this).multiselect("getChecked").length

Suppose the widget starts off with no checkboxes checked. If I check one, the alert gives me "1", meaning that the checkbo开发者_C百科x is already selected when the click handler is hit.

Now say that instead of explicitly clicking, I do what Eric Hynds suggests to fake a click-

$("select").multiselect("widget").find(":checkbox:eq(2)").trigger("click");

(I select the checkbox with the value of 2 here just for demonstration purposes.) The alert here gives me 0.

I haven't been able to figure out why there is this discrepancy and its causing issues when I'm trying to limit the number of checkboxes a user can select. They are able to check checkboxes not only by clicking them but also by clicking things outside the widget, which is why I have to fake clicks on the actual checkboxes.

Any help is appreciated, thanks!


The documentation says:

... the native click event must be used (trigger('click') will not work) due to this bug in jQuery’s core ...

so, something like this I think:

$("select").multiselect("widget").find(":checkbox:eq(2)").each(function(){  
    this.click(); 
}); 
0

精彩评论

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

关注公众号