JQuery Tab each Selected tab first text box focus

。_饼干妹妹 提交于 2020-01-15 12:42:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!