问题描述
页面填完User和Email后,页面刷新后保存下来下来,不需要再输入一遍图如下:具体代码如下:<div>//user name<input id="remote_host_input_name" type="text" style="width:260px;" onfocus="onNameFocus()" onblur="onNameBlur()" value="Full Name"/><span id="remote_host_span_name" class="remote-join-check"> <img src="./images/join_error.png" /></span><span id="remote_host_span2_name" class="remote-join-check"><img src="./images/join_pass.png" /></span></div><div class="mt-10px">//email<input id="remote_host_input_email" type="text" style="width:260px;" onfocus="onEmailFocus()" onblur="onEmailBlur()" value="Email"/><span id="remote_host_span_email" class="remote-join-check"><img src="./images/join_error.png" /></span><span id="remote_host_span2_email" class="remote-join-check"><img src="./images/join_pass.png" /></span><span id="remote_host_email_error" style="color:red"></span></div>如何添加 可以保存呢? 问题补充:remote.checkName = function(){if($('#remote_host_input_name').val() == 'Full Name'){remote.name = "";remote.cookie.setCookie("name","");return true;}else{var _name = $('#remote_host_input_name').val();remote.name = _name;remote.cookie.setCookie("name",_name);alert(remote.cookie.getCookie("name"));return true;}};这是jquery代码,alert出来的结果是null。
解决方案
function writeCookie(name, value, hours) { var expire = ""; if(hours != null) { expire = new Date((new Date()).getTime() + hours * 3600000); expire = "; expires=" + expire.toGMTString(); } document.cookie = name + "=" + escape(value)+ expire; }function readCookie(name) { var cookieValue = ""; var search = name+ "="; if(document.cookie.length > 0) { offset=document.cookie.indexOf(search); if (offset!=-1) { offset += search.length; end = document.cookie.indexOf(";",offset); if (end== -1) { end = document.cookie.length; } cookieValue = unescape(document.cookie.substring(offset, end)); } } return cookieValue; }
解决方案二:
jquery我没用过我是拿纯js写的这样是可以读到数据的