Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery选项卡cookie使用现有脚本_Jquery_Cookies_Tabs_Refresh - Fatal编程技术网

Jquery选项卡cookie使用现有脚本

Jquery选项卡cookie使用现有脚本,jquery,cookies,tabs,refresh,Jquery,Cookies,Tabs,Refresh,也许这并不难做到,但JS背景对我来说并不难理解。我正在尝试将所选选项卡存储在cookie中,所以如果页面仍然刷新,它将更早地显示所选选项卡 我已经使用列表网格布局为我的网站,也有cookie设置和工程罚款。我正在发布cookie代码,我也在使用我的标签html和javascript 列表/网格Cookie JS $(function() { var cc = $.cookie('list_grid'); if (cc == 'g') {

也许这并不难做到,但JS背景对我来说并不难理解。我正在尝试将所选选项卡存储在cookie中,所以如果页面仍然刷新,它将更早地显示所选选项卡

我已经使用列表网格布局为我的网站,也有cookie设置和工程罚款。我正在发布cookie代码,我也在使用我的标签html和javascript

列表/网格Cookie JS

    $(function() {
        var cc = $.cookie('list_grid');
        if (cc == 'g') {
            $('#listgrid').addClass('grid');
            $('#grid').addClass('current');            
        } else {
            $('#listgrid').removeClass('grid');
            $('#list').addClass('current');
        }
    });

$(document).ready(function() {

    $('#grid').click(function() {
        $(".current").removeClass("current");
        $(this).addClass("current");

        $('#listgrid').fadeOut(500, function() {
            $(this).addClass('grid').fadeIn(500);
            $.cookie('list_grid', 'g');
        });
        return false;
    });

    $('#list').click(function() {
        $(".current").removeClass("current");
        $(this).addClass("current");

        $('#listgrid').fadeOut(500, function() {
            $(this).removeClass('grid').fadeIn(500);
            $.cookie('list_grid', null);
        });
        return false;
    });

});
我的标签HTML
  • 表1
  • 表2
  • 表3

  • 因此,任何人都可以帮我做这件事。

    我认为您最好使用jquery ui选项卡


    }));​

    您是在尝试编写自己的选项卡还是使用现有的jQuery UI?我想做的是,我正在使用从任何列表/网格布局教程下载的一个cookie脚本。请参见,我想对我的选项卡UI使用相同的cookie脚本。我不知道这是否可能。我尝试过这一点,但不知为什么它不起作用,因为HTML标记与我的有点不同。我尝试过你的代码,但它甚至没有同时隐藏我的div all div display:(如果你愿意,如果你能找到我的错误,我可以给你我的所有文件。我想你很接近了,我只是想表明你应该在tab click事件中将选项卡保存在cookie(我称为“tab”)中。然后你可以在文档加载时引用该cookie(jQuery(document).ready)决定要显示哪个选项卡。Dave我感谢您的帮助和努力,但我不是表单Javascript字段,所以这太过分了。如果您能做到,我需要一些具体的帮助,我非常感谢。我提出了我的解决方案。请确保您有一个jquery cookie插件的参考。(我假设您是这样做的,因为您正在网格/列表示例中使用它。
    <div class="tabs">
    
        <div id="tab1" class="tab">
        </div>
    
        <div id="tab2" class="tab">
        </div>
    
        <div id="tab3" class="tab">
        </div>
    </div>
    
        //to fix u know who
        jQuery(".tab:first").show();
    
        //when we click one of the tabs
        jQuery(".htabs a").click(function () {
    
            $(".current").removeClass("current");
            $(this).addClass("current");
    
            //get the ID of the element we need to show
            stringref = jQuery(this).attr("href").split('#')[1];
            //hide the tabs that doesn't match the ID
            jQuery('.tab:not(#' + stringref + ')').hide();
            //fix
            if (jQuery.browser.msie && jQuery.browser.version.substr(0, 3) == "6.0") {
                jQuery('.tab#' + stringref).show();
            } else
            //display our tab fading it in
            jQuery('.tab#' + stringref).fadeIn();
            //stay with me
            return false;
    
        });
    
    });
    
    jQuery(document).ready(function () { 
    
    // get the cookie
     var tabcookie = $.cookie('tab');    
     if (tabcookie){
         jQuery('.tab:not(#' + tabcookie + ')').hide();
         jQuery('.tab#' + tabcookie ).show();    
     }else{
          jQuery(".tab:not(:first)").hide();
    
        //to fix u know who
        jQuery(".tab:first").show();
     }
    
    
    //when we click one of the tabs
    jQuery(".htabs a").click(function () {
    
        $(".current").removeClass("current");
        $(this).addClass("current");
    
        //get the ID of the element we need to show
        stringref = jQuery(this).attr("href").split('#')[1];        
        //hide the tabs that doesn't match the ID
        jQuery('.tab:not(#' + stringref + ')').hide();
    
        // save the cookie
        $.cookie('tab', stringref);
    
    
        //fix
        if (jQuery.browser.msie && jQuery.browser.version.substr(0, 3) == "6.0") {
            jQuery('.tab#' + stringref).show();
        } else
        //display our tab fading it in
        jQuery('.tab#' + stringref).fadeIn();
        //stay with me
        return false;
    
    });