表单提交后,jquery ui选项卡保持在选项卡上
嗨,我在一个有两个选项卡的页面中使用jQueryUITabs小部件。每个页面都包含一个表单,其页面与一个操作相同。 提交表单后,我需要停留在提交表单的选项卡中。 我怎样才能做到这一点 这是我的密码:表单提交后,jquery ui选项卡保持在选项卡上,jquery,html,forms,tabs,Jquery,Html,Forms,Tabs,嗨,我在一个有两个选项卡的页面中使用jQueryUITabs小部件。每个页面都包含一个表单,其页面与一个操作相同。 提交表单后,我需要停留在提交表单的选项卡中。 我怎样才能做到这一点 这是我的密码: <div id="tabs"> <ul> <li><a href="#tabs-1">Tab 1</a></li> <li><a href="#tabs-2">Tab 2</a&
<div id="tabs">
<ul>
<li><a href="#tabs-1">Tab 1</a></li>
<li><a href="#tabs-2">Tab 2</a></li>
</ul>
<div id="tabs-1">
<p>I'm Tab1.</p>
<p>I'm a Form using GET Method, passing values to this same page:<br></p>
<p><form name="input" action="index.php" method="GET">
<input type="text" name="value" id="somevalue" style="width:150px;"> <br>
</form></p>
<?
if (isset($_GET)) {echo ($_GET['value']);}
?>
</div>
<div id="tabs-2">
<p>I'm Tab2.</p>
<p>I'm a Form using GET Method, passing values to this same page:<br></p>
<p><form name="input" action="index.php" method="GET">
<input type="text" name="value2" id="somevalue" style="width:150px;"> <br>
</form></p>
<?
if (isset($_GET)) {echo ($_GET['value2']);}
?>
</div>
</div>
我是Tab1
我是一个使用GET方法的表单,将值传递到同一页面:
我是Tab2
我是一个使用GET方法的表单,将值传递到同一页面:
提前谢谢。
Sebastian您可以通过使用插件来实现这一点 您需要将所选选项卡索引保存到cookies,并在每次加载页面时读取这些cookie并选择适当的选项卡。 保存在tabs插件的处理程序中(将保存选项的值) 要在页面加载时选择所需的选项卡,您需要读取cookie并在选项卡上设置
活动选项。
这是完整的$(文档)。准备好了代码:
$(document).ready(function(){
//initialize tabs plugin with listening on activate event
var tabs = $("#tabs").tabs({
activate: function(event, ui){
//get the active tab index
var active = $("#tabs").tabs("option", "active");
//save it to cookies
$.cookie("activeTabIndex", active);
}
});
//read the cookie
var activeTabIndex = $.cookie("activeTabIndex");
//make active needed tab
if(activeTabIndex !== undefined) {
tabs.tabs("option", "active", activeTabIndex);
}
});
这是你的电话号码
(我删除了表单以使其在JSFIDLE中工作;如果您在提交表单后仍停留在同一页面上,它将工作)非常感谢像我这样仍然使用旧版本jQuery的开发人员的解释性回答:使用'select'而不是activate,使用“ui.index”检索所选索引,并使用tabs.tabs(“选择”,activeTabIndex)选择适当的选项卡。
$(document).ready(function(){
//initialize tabs plugin with listening on activate event
var tabs = $("#tabs").tabs({
activate: function(event, ui){
//get the active tab index
var active = $("#tabs").tabs("option", "active");
//save it to cookies
$.cookie("activeTabIndex", active);
}
});
//read the cookie
var activeTabIndex = $.cookie("activeTabIndex");
//make active needed tab
if(activeTabIndex !== undefined) {
tabs.tabs("option", "active", activeTabIndex);
}
});