Home  >  Article  >  Web Front-end  >  How to correctly determine whether the username cookie exists using js_javascript skills

How to correctly determine whether the username cookie exists using js_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:01:491421browse

Sometimes we need to use cookies to save user names and record login status. How to correctly determine whether the user cookie exists on this machine? You cannot simply use writing like a!=" =getCookie("username3");
c_start=document.cookie.indexOf("username3=");

if(c_start == -1){ $("#login_form").show( ); $("#logined").hide(); } else{ $("#login_form").hide(); $("#logined" ).show();
$("#ustr").html(a);
}


The correct method is: to determine whether there is a cookie named username3, use document .cookie.indexOf("username3=") to determine, if the return value is -1, it means it does not exist.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn