ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` <!DOCTYPE html> <html lang="zh"> <head> <meta charset="utf-8"> <title>Json1</title> </head> <body> <button type="button" onclick="traditional()">Set cookie 1</button> <button type="button" onclick="simplified()">Set cookie 2</button> <button type="button" onclick="all_cookie()">all_cookie</button> <button type="button" onclick="checkCookie()">check</button> <button type="button" onclick="delete_cookie_username()">delete_cookie_username</button> </body> <script> function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires="+d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } function checkCookie() { var user = getCookie("username"); if (user != "") { alert(user); } else { // setCookie("username", "Neo", 365); alert('no set username cookie') } } function traditional() { document.cookie = "username=Neo-1"; var user = getCookie("username") alert(user); } function simplified() { document.cookie = "username=Neo-2"; var user = getCookie("username") alert(user); } function all_cookie() { alert(document.cookie); } function delete_cookie_username() { document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; } </script> </html> ```