您的位置:首页 > Web前端 > HTML5

HTML5存储数据----sessionStorage保存与读取临时数据

2013-12-27 18:50 399 查看
<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>使用sessionStorage保存与读取临时数据</title>

</head>


<body>

<fieldset>

<input type="text" name="txt" id="txt" onChange="txt_Change(this)" size="30px">

<input type="button" name="btn" onClick="btn_Click()" value="读取">

<p id="pid"></p>

</fieldset>

</body>

<script type="text/javascript">


function $(id){

return document.getElementById(id);

}

function txt_Change(v){

var txtName = v.value;

//保存数据

sessionStorage.setItem("txtName",txtName);

$("pid").style.display="block";

//获取数据

$("pid").innerHTML = sessionStorage.getItem("txtName");

}

function btn_Click(){

$("pid").style.display="block";

$("pid").innerHTML = sessionStorage.getItem("txtName");

}


</script>

</html>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: