简体   繁体   中英

jQuery focus() on textbox on button click ipad

I am developing an application on the iPad using jQuery and HTML5.

I want to give focus to a textbox on a button click. The button functionality is to clear the textbox value. After clearing the value, I want the focus to be there in the textbox .

My code is:

function onclickclearbtn(){
    $('#txtbox').val('');
    $('#txtbox').focus();
}

i am using jquery 1.4.4

I'd suggest something like overlaying the button inside the textfield. Such as http://cor.to/focustest (http://fiddle.jshell.net/tomasdev/W8udu/show/light/)

Why? iOS doesn't provide a way to .focus() since it may be annoying for the user to have constantly the keyboard popped up. So it requires a real user action to the input to show the keyboard.

What we do? Just put a transparent input over the button :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM