开发者

Caret / Cursor is not [really] take focus after .focus() using JQuery

开发者 https://www.devze.com 2023-03-21 20:40 出处:网络
i\'m trying to set the focus to the next input box after the user select a value from the autocomplete drop down (using jquery).

i'm trying to set the focus to the next input box after the user select a value from the autocomplete drop down (using jquery).

so the code look like this:

function showElement(elementName) { $(elementName).show('blind', onEl开发者_高级运维ementDisplay(elementName)); }

 function onElementDisplay(elementName) {
     $(elementName).focus();
 }

so i would expect to see the cursor/caret blinking on the element that was displayed at the end of the function, hence the user can start type in, however, it doesn't happen.

anything i'm missing here?


The second argument is a callback (type Function). You are passing it the return of onElementDisplay, which would be undefined.

Add an anonymous function wrapper.

function showElement(elementName) { 
    $(elementName).show('blind', function(){
        onElementDisplay(elementName); 
    });
}

function onElementDisplay(elementName) {
    $(elementName).focus();
}
0

精彩评论

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