<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/jquery-3.5.0.js"></script>
<script src="js/jquery.cookie.js"></script>
<script type="text/javascript">
//记录cookie
$(function () {
$('input[name=btnSend]').click(function () {
//校验用户输入
var b = $('input[name=user_name]').val().length > 0 && $('input[name=user_pwd]').val().length > 0;
if (b) {
$.cookie('user_name', $('input[name=user_name]').val(), { expires:7 });
alert('欢迎:' + $('input[name=user_name]').val());
}
});
var user_name = $.cookie('user_name');
if (user_name != null) {
$('#cookie').append('欢迎' + user_name);
}
});
</script>
</head>
<body>
用户名: <input type="text" name="user_name" value="" />
密码:<input type="text" name="user_pwd" value="" />
<input type="button" name="btnSend" value="提交" />
<span id="cookie"></span>
</body>
</html>
Jquery Cookie
最新推荐文章于 2025-04-01 17:40:28 发布