开发者

focus to the beginning of the textarea on iphone?

开发者 https://www.devze.com 2022-12-18 21:15 出处:网络
The function focus() doenst开发者_C百科 seem to work for iphone? I need something similar to what they have done for gmail.com when you do a reply.If you\'re targeting iPhone/Android (... and don\'t h

The function focus() doenst开发者_C百科 seem to work for iphone? I need something similar to what they have done for gmail.com when you do a reply.


If you're targeting iPhone/Android (... and don't have to worry about Windows Phone 7 Phone 7 Phone etc.) you can take advantage of the HTML5 autofocus attribute.

So with some markup like this:

<textarea id="the-textarea" autofocus></textarea>

You get an auto-focused textarea.

If you need to position the caret inside the textarea you can use its setSelectionRange method:

$("#the-textarea")[0].setSelectionRange(0, 0);


If you are only targeting Safari, you might try checking out the Safari-specific documentation: http://developer.apple.com/safari/

Firebug (Firefox extension) can also be very helpful in looking at how other developers are implementing things on their sites.

0

精彩评论

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