Javascript 使用Jquery存储临时数据
所以我有一个聊天盒,用户可以在其中聊天。但问题是,当用户刷新之前的所有数据时,数据都会丢失 因此,有没有一种方法可以存储在textarea中输入的所有数据,并具有ind idJavascript 使用Jquery存储临时数据,javascript,jquery,html,Javascript,Jquery,Html,所以我有一个聊天盒,用户可以在其中聊天。但问题是,当用户刷新之前的所有数据时,数据都会丢失 因此,有没有一种方法可以存储在textarea中输入的所有数据,并具有ind id“chat-box-textinput”,即使在刷新时也可以显示出来 function chatRefreshState(state) { if (state) { $('#chat-box-header').text(options.onlineTitle);
“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" />'
);
}
}
}
函数状态(状态){
如果(州){
$(“#聊天室标题”).text(options.onlineTitle);
如果(!requestChat){
$(“#聊天室”).html(
'' +
“有问题吗?让我们聊天吧!在下面的字段中输入您的姓名和问题,然后按Enter键。”+
输入您的姓名+
''
);
}
}否则{
如果(!聊天编辑){
$(“#聊天室标题”).text(options.offlineTitle);
$(“#聊天室输入”).hide();
$(“#聊天室”).html(
“您的电子邮件”+
“你的留言”+
“”
);
}
}
}
非常感谢尝试html5存储或使用jquery插件 使用HTML5,网页可以在用户浏览器中本地存储数据 参考文献 jStorage=> jquery总存储=> 有用链接
您可以使用它,但这取决于您的浏览器支持
window.localStorage.setItem("testdata","yes you are");
window.localStorage.getItem("testdata");
为什么要投票???如果这听起来很愚蠢,请忽略它,而不是投反对票。谢谢