简体   繁体   English

如何在jQuery UI标签中提交表单上的选定标签

[英]how to get selected tab on form submit in jquery ui tabs

In my MVC application Im using jquery UI tabs (jquery-ui-1.9.0) and setting a tab selected using the script below 在我的MVC应用程序中,Im使用jquery UI选项卡(jquery-ui-1.9.0)并设置使用以下脚本选择的选项卡

<script type="text/javascript">
$(document).ready(function () {
    $( "#tabs" ).tabs({ selected: @Convert.ToInt32(Model.SearchModel.SearchType) })
});

<div id="tabs">
 <ul>
   <li><a href="#articlesearchtab">Article</a></li>
   <li><a href="#othersearchtab">Other</a></li>
 </ul>

<div id="articlesearchtab">
   //content
</div>

<div id="othersearchtab">
   //content
</div>

User can go into either tab and update content. 用户可以进入任一标签页并更新内容。 I need to get the content of selected tab on form submit. 我需要获取表单提交上选定选项卡的内容。 How can I get know the tab where user has selected? 我如何知道用户选择的选项卡?

In jQuery UI 1.9, the selected option is deprecated: 在jQuery UI 1.9中,不赞成使用所选的选项:

Deprecated selected option; 不推荐使用的选项; renamed to active 重命名为活动

(#7135) The selected option has been renamed to active for consistency with other plugins in jQuery UI. (#7135)为与jQuery UI中的其他插件保持一致,已将所选选项重命名为active。 You should replace all uses of the selected option with the active option. 您应将所有使用的选定选项替换为活动选项。

The selected option will be removed in 1.10. 所选的选项将在1.10中删除。

Here is the new way to get the current tab: 这是获取当前标签的新方法:

Boolean: Setting active to false will collapse all panels. 布尔值:将active设置为false将折叠所有面板。 This requires the collapsible option to be true. 这要求可折叠选项为true。 Integer: The zero-based index of the panel that is active (open). 整数:活动(打开)的面板的从零开始的索引。 A negative value selects panels going backward from the last panel. 负值选择从最后一个面板倒退的面板。

Code examples: 代码示例:

Initialize the tabs with the active option specified: 使用指定的活动选项初始化选项卡:

 $( ".selector" ).tabs({ active: 1 }); 

Get or set the active option, after initialization: 初始化后获取或设置活动选项:

 // getter var active = $( ".selector" ).tabs( "option", "active" ); // setter $( ".selector" ).tabs( "option", "active", 1 ); 

Simply, Call Same tabs in javascript using Code behind where you submit the form. 只需在提交表单的后面使用代码在javascript中调用“相同”标签。

<script type="text/javascript" language="javascript">
    function OpenMoreDetails(id) {
        document.getElementById(id).style.display = 'block';
        return false;
    }
</script>

protected void btnAttachDocument_Click(object sender, EventArgs e)
{

    //your code     
    ScriptManager.RegisterStartupScript(this, GetType(), "attach",  "OpenSearchOption('yourtabid',this);", true);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM