开发者

jquery, set focus on the first enabled input or select or textarea on the page

It's fairly straightfo开发者_如何学编程rward. I want to set focus to the first enabled and not hidden control on the page.

For a textbox, I have

$("input[type='text']:visible:enabled:first").focus();

But I want to get "all" form input controls: textbox, checkbox, textarea, dropdown, radio in my selector to grab the first enabled and not hidden control. Any suggestions?


$(':input:enabled:visible:first').focus();


As an extension of Jordan's answer

$(':input:enabled:visible:not([readonly]):first').focus();

This one also excludes readonly inputs


This is a little more comprehensive:

$('form :input:text:visible:not(input[class*=filter]):first').focus();

Lamen: Focus the cursor in the first text input in a form that is visible, but if it use the class named "filter", ignore it!


Try this:

$("input[type='text']:enabled","another selector","another selector").first().focus();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜