日期:2014-05-18 浏览次数:20420 次
function SetCookie(name,value) { var key=''; var Days = 2; var exp = new Date(); var domain = ""; exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000); if (key == null || key == "") { document.cookie = name + "=" + encodeURI(value) + ";expires=" + exp.toGMTString() + ";path=/;domain=" + domain + ";"; } else { var nameValue = GetCookie(name); if (nameValue == "") { document.cookie = name + "=" + key + "=" + encodeURI(value) + ";expires=" + exp.toGMTString() + ";path=/;domain=" + domain + ";"; } else { var keyValue = getCookie(name, key); if (keyValue != "") { nameValue = nameValue.replace(key + "=" + keyValue, key + "=" + encodeURI(value)); document.cookie = name + "=" + nameValue + ";expires=" + exp.toGMTString() + ";path=/;domain=" + domain + ";"; } else { document.cookie = name + "=" + nameValue + "&" + key + "=" + encodeURI(value) + ";expires=" + exp.toGMTString() + ";path=/;" + domain + ";"; } } } } function GetCookie(name) { var nameValue = ""; var key=""; var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) { nameValue = decodeURI(arr[2]); } if (key != null && key != "") { reg = new RegExp("(^| |&)" + key + "=([^(;|&|=)]*)(&|$)"); if (arr = nameValue.match(reg)) { return decodeURI(arr[2]); } else return ""; } else { return nameValue; } }
------解决方案--------------------
//保存用户条件 var key = "<%=key %>"; var stardate = "<%=stardate %>"; var dataend = "<%=dataend %>"; if (document.getElementById("serchinput").value == "") { document.getElementById("serchinput").value = key; } if (document.getElementById("datastart").value == "") { document.getElementById("datastart").value = stardate; } if (document.getElementById("dataend").value == "") { document.getElementById("dataend").value = dataend; } </script>