核心代码如下:
代码语言:javascript复制<script>
function storageObj(obj) {
var checkedIdStr = JSON.stringify(obj);
sessionStorage.setItem("search_logs", checkedIdStr);
};
var arrBefor = [];
if(sessionStorage.getItem("recode_search_logs")){
arrBefor = JSON.parse(sessionStorage.getItem("search_logs"));
}
<?php if(isset($_GET['s']) && $_GET['s']){?>
arrBefor.unshift({"key":"<?php echo $_GET['s'];?>", "date":"<?php echo date("m-d H:i");?>"});
<?php }?>
storageObj(arrBefor);
//var arrAfter = JSON.parse(sessionStorage.getItem("recode_search_logs"));
//console.log(arrAfter,typeof arrAfter);
</script>