<div class="codetitle"> <span><a style="CURSOR: pointer" data="46513" class="copybut" id="copybut46513" onclick="doCopy('code46513')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code46513"> <br> <br> <br> <br><title>cookies.html</title> <br><br><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <br><meta http-equiv="description" content="this is my page"> <br><meta http-equiv="content-type" content="text/html; charset=UTF-8"> <br><br><style type="text/css"> <BR>.txt{ <BR>width: 150px; <BR>height:20px; <BR>border: 1px blue solid; <BR>border-radius:0.5em; <BR>margin-bottom: 5px; <BR>padding-left: 5px; <BR>} <br><br></style> <br><script type="text/javascript" src="../js/jquery-1.10.2.js"></script> <br><script type="text/javascript" src="../js/jquery.cookie.js"></script> <br><script type="text/javascript"> <BR>$(function(){ <br><br><BR>if($.cookie("name")){ <BR>//取值如果存在则赋值 <BR>$("#username").val($.cookie("name")); <br><br>} <br><br><BR>$("#mycookie").submit(function(){ <br><br>//如果选中了保存用户名选项 <BR>if($("#chkSave").is(":checked")){ <br><br>//设置Cookie值 <BR>$.cookie("name",$("#username").val(),{ <BR>expires:7,//设置保存期限 <BR>path:"/"//设置保存的路径 <br><br>}); <br><br>}else{ <br><br>//销毁对象 <BR>$.cookie("name",null,{ <BR>path:"/" <br><br>}); <BR>} <br><br>return false; <BR>}); <br><br>}); <br><br><BR></script> <br> <br> <br><form action="#" method="get" id="mycookie"> <br><br><div> <br>用户名:<br> <br><input id="username" name="username" type="text" class="txt"> <br> </div> <br><div> <br>密码:<br> <br><input id="password" name="password" type="password" class="txt"> <br> </div> <br><div> <br><input id="chkSave" type="checkbox">是否保存用户名 <br> </div> <br><div> <br><input id="cookBtn" class="btn" type="submit" value="提交"> <br> </div> <br><br> </form> <br> <br> <br> </div>