select刷新后,保持选定状态,Cookies存储select选定状态信息

    //cookies存储select选定值,防止刷新后没了
window.onload = function () {
var cooki = document.cookie;
if (cooki != "") {
cooki = "{\"" + cooki + "\"}";
cooki = cooki.replace(/\s*/g, "").replace(/=/g, '":"').replace(/;/g, '","');
var json = eval("(" + cooki + ")"); //将coolies转成json对象
document.getElementById("pselect").options[json.selIndex].selected = true;//保持原来的选项
}else
save();
} function selectP(){
var options=$("#pselect option:selected");
var selectP=options.val();
selectIndex = document.getElementById("pselect").selectedIndex;
document.cookie = 'selIndex =' + selectIndex;//保存在cookie中,键名为selIndex //alert(p);
$.ajax(
{
type:"post",
url:"<%=basePath%>servlet/UserServlet",
data:"oper=6&selectP=" + selectP,
success:function(data) {
//alert(data); location.reload(); }
});
}
上一篇:(42)嵌入式项目中常用到的C语言技能总结


下一篇:Python学习笔记(Ⅱ)——循环/选择/函数