頁面代碼:
<!DOCTYPE HTML>
<html>
<head>
<title>cookie test</title>
<script type="text/javascript" src="jquery/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="jquery/jquery.cookies.2.2.0.min.js"></script>
<script type="text/javascript" src="js/cookie.js"></script>
</head>
<body>
<div>
<form action="" method="post">
用戶名:<input type="text" id="uname" value="${cookie.uname}"/><br>
密 碼:<input type="password" id="upwd" value="${cookie.upwd}"/><br>
<input type="submit" id="sub" value="提交" style="margin-left:163px; "/>
</form>
</div>
</body>
</html>
js代碼:
$(function(){
$("#sub").click(function(){
alert($("#uname").val()+' '+$("#upwd").val());
$.cookie($("#uname").val(), $("#uname").val(),{expires:10});
$.cookie($("#upwd").val(), $("#upwd").val(),{expires:10});
alert('cookie saved');
});
});
cookie saved沒彈出來 cookie沒創建成功 求大神指教
先看你的按鈕點擊函數是否執行。$("#uname").val(),是否有數據