开发者

Jquery event for select tag closing

开发者 https://www.devze.com 2023-01-11 11:30 出处:网络
I can hook into the change event of the select fine (Which will cause the select to close), which is not a problem. But I also need to detect when the select tag is closed by way开发者_运维百科 of cli

I can hook into the change event of the select fine (Which will cause the select to close), which is not a problem. But I also need to detect when the select tag is closed by way开发者_运维百科 of clicking on the screen elsewhere.

So far everything I've tried hasn't worked; body click, body focus, select blur, select focusout are among the few combinations.

With most of them it will only register on the second click on the body, so: Click1) Select closes, event doesn't fire. Click2) Event fires.

I know I could create my own version of a select tag (And have done so before), but it seems a bit overkill for this situation when the normal select is fine, I just need this one event.

Cheer, Psy


Sounds like a blur thang...

$('select').on('change', function() {
    //change things here 
}).on('blur', function() {
    //when select is no longer in focus here
});

Made a fiddle

0

精彩评论

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

关注公众号