使用Jquery存储临时数据

时间:2014-06-19 06:39:24

标签: javascript jquery html

我有聊天框,用户可在其中聊天。但问题是当用户刷新所有以前的数据丢失时。

有没有办法可以存储在textarea havind id 'chat-box-textinput'中输入的所有数据,并在刷新时显示回来。

 function chatRefreshState(state) {
            if (state) {
                $('#chat-box-header').text(options.onlineTitle);
                if (!requestChat) {
                    $('#chat-box').html(
                        '<div id="chat-box-msg" style="height:225px;overflow:auto;">' +
                        '<p>Have a question? Let\'s chat!</p><p>Enter your Name & Question in the field\'s below and press ENTER.</p>' +
                        '<p style="margin-top:10px;">Enter Your Name</p><input type="text" id="chat-box-name" style="border:1px solid #0354cb;border-radius: 3px;width: 100%;height:30px;" class="chat-editing" /></div>' +
                        '<div id="chat-box-input" ><textarea id="chat-box-textinput" style="width:100%;height:45px;border:1px solid #0354cb;border-radius: 3px;" /></div>'
                    );
                }
            } else {
                if (!chatEditing) {
                    $('#chat-box-header').text(options.offlineTitle);
                    $('#chat-box-input').hide();
                    $('#chat-box').html(
                        '<p>Your email</p><input type="text" id="chat-box-email" style="border:1px solid #0354cb;border-radius: 3px;width: 100%;" class="chat-editing" />' +
                        '<p>Your message</p><textarea id="chat-box-cmt" cols="40" rows="7" class="chat-editing" style="border:1px solid #0354cb;border-radius: 3px;"></textarea>' +
                        '<p><input type="button" id="chat-box-send" value="Contact us" />'
                    );
                }
            }
        }

非常感谢

2 个答案:

答案 0 :(得分:1)

尝试html5存储或使用jquery插件

  

使用HTML5,网页可以在用户的​​浏览器中本地存储数据。

REFERENCE http://www.w3schools.com/html/html5_webstorage.asp

jStorage =&gt; http://www.jstorage.info/

jquery-total-storage =&gt;  https://github.com/Upstatement/jquery-total-storage 有用的链接

http://plugins.jquery.com/tag/storage/

答案 1 :(得分:0)

您可以使用此功能,但这取决于您的浏览器支持。

 window.localStorage.setItem("testdata","yes you are");

 window.localStorage.getItem("testdata");
相关问题