[英]Make Tab Active Programmatically
I am trying to make a certain tab made active programmatically when the div is made visible using the following: 我试图使用以下方法使div可见时以编程方式激活某个选项卡:
$("#myTab").tabs("option", "active", 0); // Focus on Employee Tab
When using this I receive the following console.log message: 使用此方法时,我收到以下console.log消息:
Error: cannot call methods on tabs prior to initialization; 错误:初始化前无法在标签上调用方法; attempted to call method 'option' 试图调用方法“选项”
This code has been placed in the document ready script. 此代码已放置在文档就绪脚本中。 Thanks for any help. 谢谢你的帮助。 :) :)
You can try to manually trigger a click event on a specific tab:- 您可以尝试在特定标签上手动触发点击事件:-
var tabname = "employee";
tabEL = $('#myTav [data-tab-name="'+ tabName +'"]');
tabEL.click();
Use this method, 使用这种方法
$("#myTab").tabs({active : <tab number>});
or 要么
$("#myTab").tabs({active : 0});
Demo With your code . 演示与您的代码 。
In your case you need to initialize the tabs first. 在您的情况下,您需要首先初始化选项卡。 If you don't you get an error, as you are directly calling a function on tabs. 如果不这样做,则会因为直接在选项卡上调用函数而出现错误。
$("#myTab").tabs(); //initialize
$("#myTab").tabs("option", "active", 0); //set tab
or 要么
$("#myTab").tabs().tabs("option", "active", 0);
For some reason this code is executed before the tab are initialize. 由于某种原因,该代码在选项卡初始化之前执行。 Assumimg you're using jQuery UI tabs. 假设您正在使用jQuery UI选项卡。 Check if you got $("myTab").tabs();
检查您是否有$("myTab").tabs();
before the activation code. 激活码之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.