微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用jQuery提交表单后,保持当前选项卡

我正在尝试保留一个特定的选项卡(在本例中为tab2),但在单击提交按钮后,选项卡将恢复为具有认活动类的选项卡1.我用这个打了一堵砖墙.

这是我的例子[jsfiddle]

HTML:

    odo. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae.

JavaScript的:

$(document).ready(function(){
    $('ul.tabs').each(function(){
        var $active,$content,$links = $(this).find('a');
        $active = $links.first().addClass('active');
        $content = $($active.attr('href'));
        $links.not(':first').each(function () {
            $($(this).attr('href')).hide();
        });

        $(this).on('click','a',function(e){
            $active.removeClass('active');
            $content.hide();
            $active = $(this);
            $content = $($(this).attr('href'));
            $active.addClass('active');
            $content.show();
            e.preventDefault();
        });
    });
});

CSS:

*         {padding:0; margin:0;}
html      {padding:15px 15px 0;font-family:sans-serif;font-size:14px;}
p,h3     {margin-bottom:15px;}
div       {padding:10px;width:600px;background:#fff;}
ul.tabs   {margin-left:2px;}
#tab1,#tab2 {border-top: solid 1px #ccc;margin-top: -1px; }
#tab2      {display:none;}a
ul.tabs li  {list-style:none;display:inline;}
ul.tabs li a   {padding:5px 10px;display:inline-block;background:#666;color:#fff;text-decoration:none;}
ul.tabs li a.active {background:#fff;color:#000;border: solid 1px #ccc; border-width: 1px 1px 0 1px;}

非常感谢您的帮助

最佳答案

Try this

dionIndex" runat="server" Value="0" />

将其放入编码中并按如下方式更改脚本

$("#accordion").accordion({
header: "h3",autoHeight: false,event: "mousedown",active: activeIndex,ui: "PageName.aspx",change: function (event,ui) {
var index = $(this).accordion("option","active");
$('#<% =hidAccordionIndex.ClientID %>').val(index);
}
});

原文地址:https://www.jb51.cc/jquery/428096.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐