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

How to write if in jquery

藏色散人
Release: 2023-01-04 09:36:46
Original
4984 people have browsed it

How to write if in jquery: 1. Use "if($num=="1"){}else{};"; 2. Use "$num=="1"?alert(1 ):alert(0);" writing method.

How to write if in jquery

The operating environment of this tutorial: windows7 system, jquery version 1.10.0, thinkpad t480 computer.

Recommended: "jquery video tutorial"

jquery writing if statement

The first way to write (I usually Written like this):

if($num=="1"){
        alert(1);
}else{
        alert(0);    
};
Copy after login

The second way of writing:

$num=="1"?alert(1):alert(0);
Copy after login

From a specification point of view, the first type is more commonly used in products, because maintenance and upgrades must be considered, and it must be easy to read; from If the code is concise and the statements are not long, use the second method. It is recommended for general projects for rapid development.

The above is the detailed content of How to write if in jquery. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!