Home > Web Front-end > JS Tutorial > body text

Checkbox selection judgment code analysis_javascript skills

WBOY
Release: 2016-05-16 16:44:50
Original
949 people have browsed it

Copy code The code is as follows:

var xieYi=document.getElementById("xieYi");
if(!xieYi.checked){
alert("Please read and check the registration agreement first!");
return;
}

It was originally written like this, but not all situations require checking this agreement. Sometimes the agreement will not be displayed on the front page, so I changed it to the second one

Copy code The code is as follows:

var xieYi=document.getElementById("xieYi");
if(!xieYi== null && !xieYi.checked){
alert("Please read and check the registration agreement first!");
return;
}

When xieYi does not exist, xieYi is null. When it is judged that xieYi is not null and xieYi is not checked, it will alert.

Unfortunately, this code did not work as expected.

Finally, I found out that I had written xieYi wrong.

Final version:

Copy code The code is as follows:

var xieYi=document.getElementById("xieYi");
if(xieYi!= null && !xieYi.checked){
alert("Please read and check the registration agreement first!");
return;
}
Related labels:
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