【问题标题】:localStorage not working on Mozilla Firefox 22.0 for Ubuntu Canconical 1.0localStorage 不适用于 Ubuntu Canconical 1.0 的 Mozilla Firefox 22.0
【发布时间】:2013-08-17 09:26:42
【问题描述】:

我有一个网页,上面有两张表格。按钮位于它们下方。当我单击按钮时,我使用淡入/淡出切换表单显示/隐藏。我添加了该功能,这样即使我刷新页面,第一个是当前表单的表单仍然是当前表单。为此,我使用了 html5 localStorage。我在 Chrome 中运行良好,但在 Mozilla Firefox 22.0 for Ubuntu Canconical 1.0 中无法运行。

jsFiddle.

HTML:

<section id="content">
    <div id="logo" style="margin-left: 0;"></div>
    <div id="container">
        <form id="sign_up" action="login.php" method="post">
            <table style="margin: 0px auto;">
                <tr>
                    <td align="center"> <span style="font-weight: bold;font-size: 2em; color: Gray;">Sign Up</span>

                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="text" placeholder="Username" name="username" required="required" maxlength="15" pattern="^[A-Za-z0-9_]{1,15}$" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="password" placeholder="Password" name="password" required="required" />
                        <br />
                    </td>
                </tr>
                <tr>
                    <td>
                        <input class="input" type="password" placeholder="Confirm Password" name="confirm_password" required="required" />
                        <br />
                    </td>
                </tr>
                <tr>
                    <td>
                        <br/>
                    </td>
                </tr>
                <tr align="right">
                    <td>
                        <input class="btn" type="submit" value="Sign Up" name="submit_sign_up">
                    </td>
                </tr>
            </table>
        </form>
        <form id="sign_in" action="login.php" method="post">
            <table style="margin: 0 auto;">
                <tr>
                    <td align="center"> <span style="font-weight: bold;font-size: 2em; color: Gray;">Sign In</span>

                    </td>
                    <tr>
                        <td>
                            <input class="input" type="text" placeholder="Username" name="username" required="required" maxlength="15" pattern="^[A-Za-z0-9_]{1,15}$" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input class="input" type="password" placeholder="Password" name="password" required="required" />
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <br/>
                        </td>
                    </tr>
                    <tr align="right">
                        <td>
                            <input class="btn" type="submit" value="Sign In" name="submit_sign_in">
                        </td>
                    </tr>
            </table>
        </form>
        <br/>
        <input id="sign_up_btn" class="btn" type="submit" style=" font-weight:bold; height:40px; width: 292px;" value="Create An Account"></input>
    </div>
</section>

CSS:

#content {
    margin-top: 10%;
}
#container {
    margin: 0 auto;
    width: 80%;
    text-align: center;
}
input[type=text], input[type=password] {
    width: 250px;
    min-height: 25px;
    border-radius: 3px;
    border: 0;
    padding: 7px;
    font-family: Calibri;
    font-size: 20px;
    box-shadow: 0px 0px 3px 1px #aaa inset;
    box-sizing: border-box;
}
#sign_in, #sign_up {
    border: 1px solid #4f4f4f;
    border-radius: 10px;
    margin: 0 auto;
    max-height: 250px;
    width: 292px;
    padding: 10px;
    background-color: #eee;
    border: 0px;
    box-shadow: 0px 0px 15px 1px #000;
}
#sign_up {
    display: none;
    max-height: 275px;
}

JS:

jQuery(function ($) {

    var $sUp = $("#sign_up"),
        $sIn = $("#sign_in");

    $("#content").on('click', "#sign_up_btn", function () {

        $sIn.stop().fadeOut(800, function () {
            $sUp.fadeIn(800);
        });
        $(this).stop().fadeOut(800, function () {
            $(this).attr({
                value: "Already have an account?",
                id: "sign_in_btn"
            }).fadeIn(800);
        });
        localStorage.setItem('lastForm', 'sign_up');
    }).on('click', "#sign_in_btn", function () {

        $sUp.stop().fadeOut(800, function () {
            $sIn.fadeIn(800);
        });
        $(this).stop().fadeOut(800, function () {
            $(this).attr({
                value: "Create An Account",
                id: "sign_up_btn"
            }).fadeIn(800);
        });
        localStorage.setItem('lastForm', 'sign_in');
    });

    if (localStorage.getItem('lastForm') == "sign_up") {
        $sIn.fadeOut(0);
        $sUp.fadeIn(0);
    }
});

如何使cross-browser 兼容?

【问题讨论】:

    标签: javascript html cross-browser mozilla


    【解决方案1】:

    试试这个:

    localstorage.lastform="sign_in";

    【讨论】:

    • 我试过了,但它不起作用!我也尝试了 localStorage.setItem 但没有运气:(
    猜你喜欢
    • 2012-08-09
    • 2012-12-12
    • 2019-12-28
    • 2012-08-01
    • 2015-11-18
    • 2016-12-30
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    相关资源
    最近更新 更多