I know that many people actually need this function when developing websites, which is to control users to keep clicking! So I will briefly write here about the operation of COOkie based on javascript!
//Set cookie
function setCookie(key, value) {
document.cookie = key "=" escape(value);
}
//Get the value of cookie
Function getCookie(key) {
If (document.cookie.length) {
var cookies = ' ' document.cookie;
var start = cookies.indexOf(' ' key '=');
If (start == -1) { return null; }
var end = cookies.indexOf(";", start);
If (end == -1) { end = cookies.length; }
end -= start;
var cookie = cookies.substr(start,end);
return unescape(cookie.substr(cookie.indexOf('=') 1, cookie.length - cookie.indexOf('=') 1));
}
else { return null; }
}
Then let me give you a simple example! That’s it
//According to the id passed in according to the click
function comment(id,is){
If(getCookie(id)==null){
setCookie(id,"
www.widuu.com");
alert("Cookie set successfully");
}else{
If(getCookie(id)=="
www.widuu.com"){
alert("You have already reviewed");
return ;
}
//Here is your own logic to save the value to the database through ajax
}
Although this function is very simple, it is very practical. If necessary, use it to modify it! Take a screenshot for everyone to see!
Have you implemented the functions that friends often need? It's very simple. If you need it, just take it and use it.