用于jQuery切换事件和cookie的单独按钮

用于jQuery切换事件和cookie的单独按钮,jquery,cookies,width,toggle,Jquery,Cookies,Width,Toggle,我已经做了一个jQuery切换,用户可以选择主题的宽度是流动的或固定的切换按钮。 这一切都很好,但我想添加单独的切换按钮,一个用于单击固定宽度,另一个用于单击流体宽度 我试过了,但没有成功 这是我使用的代码 $(document).ready(function () { var setWidth = $.cookie("width"); if (typeof setWidth !== "undefined" && setWidth == "85%") { $('#c

我已经做了一个jQuery切换,用户可以选择主题的宽度是流动的或固定的切换按钮。 这一切都很好,但我想添加单独的切换按钮,一个用于单击固定宽度,另一个用于单击流体宽度

我试过了,但没有成功

这是我使用的代码

   $(document).ready(function () {
var setWidth = $.cookie("width");
if (typeof setWidth !== "undefined" && setWidth == "85%") {
    $('#container,.wrp').width(setWidth); // 85% width set using cookie
} else if (typeof setWidth !== "undefined" && setWidth == "960px") {
    $('#container,.wrp').width(setWidth); // 960px,1000px(for wrp) width set using cookie
}
$('#toggle-button').click(function () {
    var toggleWidth = $("#container").width() == 960 ? "85%" : "960px";

    $('#container, .wrp').animate({
        width: toggleWidth
    });
    $.cookie('width', toggleWidth);
});
});
这是小提琴:


谢谢。

您可以使用新按钮添加另一个按按功能

$('#toggle-button-resp').click(function () {
    var toggleWidth = "85%";

    $('#container, .wrp').animate({
        width: toggleWidth
    });
    $.cookie('width', toggleWidth);
});

您好,非常感谢您的帮助。是的,我试过这个,它是有效的,但我的意思是,有没有可能切换开关会是这样的:如果单击“固定”,则“固定”将被隐藏,并且在同一块中,显示“流体”按钮。就像按钮重叠一样。我希望你明白我说的话。谢谢我的意思是这里有一把小提琴的例子:@Emanuele Parisio谢谢。切换.hidden类,如果可以,请不要使用内联样式