Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 17:01:49
Original
1435 people have browsed it

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.
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template