尝试计算如何构建一个函数,其中包括等待显示引导选项卡然后继续该函数的步骤。可以使用显示的事件,但只希望在执行功能时执行此操作。任何提示?
基本代码:
function test(){
$('a[href="#tab1"]').tab('show'); //go to tab
$("a[href='#tab1']").on('shown.bs.tab', function(e) {
//do something else. However this is carried out also outside of function...only want it carried out inside function
});
}
答案 0 :(得分:0)
如何将拆分函数分为两部分,显示选项卡之前运行的部分以及仅显示选项卡之后运行的部分。
HIH
function test(){
//run first part
$('a[href="#tab1"]').tab('show'); //go to tab - I assume this line triggers the tab to be shown, right? otherwise you could use this one:
//next line *will* actually execute the code inside the event handler
$('a[href="#tab1"]').trigger('shown.bs.tab'); //go to tab
}
//this code runs on page load BUT...
$("a[href='#tab1']").on('shown.bs.tab', function(e) {
//...code in here runs only when this line runs: $('a[href="#tab1"]').trigger('shown.bs.tab');
//run second part
});