问题
How to set focus to each jQuery UI tabs first textbox? I tried like:
var frmObjAT = $j('input[type=button]').closest("form");
$j("input[type='text']:first", frmObjAT).focus();
First got focus but other tabs not focused.
回答1:
Kanishka is right but you have to wrap it with Tabs select event
$( ".selector" ).tabs({
select: function(event, ui) {
$(this).find("input[type='text']:first").focus();
}
});
Hope this help.
Edit reply to comment.
Jquery added class to hidden tab you can use that.
I tried this works
$("#tabs .tabs").not(".ui-tabs-hide").find("input[type='text']:first").focus();
回答2:
this event should fire when the tab is clicked
$('.tab').click(function(){
$(this).parents("form").find("input[type='text']:first").focus();
});
this should work
UPDATE
are those dynamically generated forms, if they are dynamically generated use
live()
$('.tab').live('click',function(){
$(this).parents("form").find("input[type='text']:first").focus();
});
来源:https://stackoverflow.com/questions/8178898/jquery-tab-each-selected-tab-first-text-box-focus