how to automatically close mobile select box when an option change event is fired?

谁说我不能喝 提交于 2019-12-08 08:57:21

问题


Testing on Android 4.0.2 if I open a select menu and pick an option the change event fires ok but I have to click the done button of the menu to close the it. Is it possible to trigger this when an option has been selected? so far I've tried adding .focus() and .blur() to the body to shift focus but with no success.

This is the snippet of code I've been testing:

$('select').on('change', function(e){ 
    console.log( $(this).find("option:selected").data('id') ); 

    $('body').blur();
    e.preventDefault(); 
});

Also jsfiddle: http://jsfiddle.net/dnRZc/5/


回答1:


Try this it worked for me.

$('select').on('change', function(e){ 
   $(this).blur();
   e.preventDefault(); 
});


来源:https://stackoverflow.com/questions/12899330/how-to-automatically-close-mobile-select-box-when-an-option-change-event-is-fire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!