function recordCookie($container, flag, prefix){
$.cookie(flag,"recorded");
$(":input", $container).each(function(){
var $inputTarget = $(this);
var id = (prefix || "") + $(this).attr("id");
var value = "";
var type= $(this).attr("type");
switch(type){
case "checkbox":
value = $inputTarget.attr("checked");
$.cookie(id, value);
break;
case "radio":
value = $inputTarget.attr("checked");
$.cookie(id, value);
break;
case "text":
value = $inputTarget.val();
$.cookie(id, value);
break;
case "select":
value = $inputTarget.get(0).selectedIndex;
$.cookie(id, value);
break;
case "select-one":
value = $inputTarget.get(0).selectedIndex;
$.cookie(id, value);
break;
};
});
};
function recoverCookie($container, flag, prefix){
if($.cookie(flag) == "recorded"){
$(":input", $container).each(function(){
var $inputTarget = $(this);
var id = (prefix || "") + $(this).attr("id");
var value = "";
var type= $(this).attr("type");
switch(type){
case "checkbox":
value = $.cookie(id) == "true" ? true : false;
$inputTarget.attr("checked", value);
break;
case "radio":
value = $.cookie(id) == "true" ? true : false;
$inputTarget.attr("checked", value);
break;
case "text":
value = $.cookie(id) || "";
$inputTarget.val(value);
break;
case "select":
var selectIndexValue = $.cookie(id) || 0;
$("option:eq("+selectIndexValue+")", $inputTarget).attr("selected",true);
break;
case "select-one":
var selectIndexValue = $.cookie(id) || 0;
$("option:eq("+selectIndexValue+")", $inputTarget).attr("selected",true);
break;
};
});
}
}
记录页面的cookie值
最新推荐文章于 2023-02-28 17:52:35 发布