jquery autocomplete remove focus after suggest

断了今生、忘了曾经 提交于 2019-12-10 12:19:45

问题


After selecting an item in the autocomplete list, my script validates the selection but does not release the focus. Ive even tried to place focus on another element to my dissapointment.

This is my code:

var usernames = [<? print_r($jquery_usernames); ?>];
            $("#suggest1").autocomplete(usernames); 
            $("#suggest1").result(function() {
                    $(this).submit();
                    setTimeout(function() {
                      $('#focusdiv').focus();
                    }, 1);                  
                });

Any suggestions?


回答1:


This is interesting and works (the focus is removed from the suggest1 input):

$("#suggest1").autocomplete(usernames); 
        $("#suggest1").result(function() {
                $(this).submit();                   
                setTimeout(function() {
                  $('.next-step').focus();
                }, 1);                  
            });

Note: It doesnt work without the setTimeout function. '.next-step' is a clickable href (tabbed form)




回答2:


Can you use the blur event? I.E. $('#suggest1').blur();



来源:https://stackoverflow.com/questions/5834990/jquery-autocomplete-remove-focus-after-suggest

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