Home >Web Front-end >JS Tutorial >How to write if in jquery
How to write if in jquery: 1. Use "if($num=="1"){}else{};"; 2. Use "$num=="1"?alert(1 ):alert(0);" writing method.
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); };
The second way of writing:
$num=="1"?alert(1):alert(0);
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!