<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="../Scripts/jquery.cookie.js" type="text/javascript"></script>
<script type="text/javascript">
//ready事件
$(function () {
//获得cookie中存储的username
var tmp = $.cookie("username");
//如果tmp存在
if (tmp) {
//将该值复制给文本框
$("#_userName").val(tmp);
}
//提交按钮事件
$(":submit").click(function (e) {
//获得文本框的值
var userName = $("#_userName").val();
//如果值是空
if (userName.length == 0) {
//阻止表单提交
e.preventDefault();
}
else {
//判断是否保存
if ($(":checkbox").attr("checked")) {
//(存储的key,value,保存的天数)
$.cookie("username", userName, { expires: 7 });
}
}
});
});
</script>
</head>
<body>
<input id="_userName" />
<input type="checkbox" id="saveUserName" />保存用户名
<input type="submit" id="login" />
</body>
</html>