jQuery的模拟点击选项卡与code执行 [英] jQuery simulate click on tab with code execution
问题描述
在code以下,当我点击一个选项卡上,我做了后并将结果显示在标签。在某些情况下,我想迫使选定的选项卡,但不是唯一的选择选项卡,但选择的选项卡+执行执行code,当我点击它。
The code below, when I click on a tab, I do a post and display the result in the tab. In some case, I'd like force the selected tab, but not only select the tab but select the tab + execute the code executed when I click on it.
在我为例,我想选择第二个选项卡(jLikeToSet = 1),并执行code:
In my exemple, I like select the second tab (jLikeToSet = 1) and execute the code :
$.post('/Home/e2', function (data) {
$('#tabs-2').html(data);
});
jQuery的:
jQuery :
var $tabs = $("#tabs").tabs();
var jLikeToSet = 1
$("#tabs").bind('tabsselect', function (event, ui) {
switch (ui.index) {
case 0:
$.post('/Home/e1', function (data) {
$('#tabs-1').html(data);
});
break;
case 1:
$.post('/Home/e2', function (data) {
$('#tabs-2').html(data);
});
break;
case 2:
$.post('/Home/e3', function (data) {
$('#tabs-3').html(data);
});
break;
}
});
HTML:
HTML:
<div id="tabs">
<ul>
<li><a href="#tabs-1">Screen 1</a></li>
<li><a href="#tabs-2">Screen 2</a></li>
<li><a href="#tabs-3">Screen 3</a></li>
</ul>
<div id="tabs-1"></div>
<div id="tabs-2"></div>
<div id="tabs-3"></div>
</div>
我怎样才能做到这一点?
How can I do this ?
谢谢
UPDATE1:
我试图用这个code:
$('#标签)tabsClick(1);
,但没有工作,样品来自这里的 http://www.eduteka.org/ajax/tabs3/
Update1 :
I tried to use this code :
$('#tabs').tabsClick(1);
but no work, sample come from here http://www.eduteka.org/ajax/tabs3/
推荐答案
要选择编程选项卡,调用该函数 jLikeToSet
ARG:
To select programmatically a tab, call this function with jLikeToSet
arg:
function selectTab(jLikeToSet){
$("#tabs").tabs( "select" , jLikeToSet);
}
当执行该功能,就好像你手动选择,所以里面有什么 .bind('tabsselect
将被执行。
when this function is executed, it's as if you have selected manually, so what's inside .bind('tabsselect'
will be executed.
这篇关于jQuery的模拟点击选项卡与code执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!