Home  >  Article  >  Web Front-end  >  How to write if in jquery

How to write if in jquery

藏色散人
藏色散人Original
2020-12-11 09:34:595006browse

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);    
};

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!

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