Use of ternary operators in js and js ternary Operators

Source: Internet
Author: User

Use of ternary operators in js and js ternary Operators

The outer layer is false, which is determined step by step to the inner layer.

 

$ Scope. nums = 700;
$ Scope. result = ($ scope. nums> 300 )? ($ Scope. nums> 400 )? ($ Scope. nums> 500 )? ($ Scope. nums> 600 )? 'Airplane ': 'high-speed rail': 'auto': 'coach ': 'no ';
Console. log ($ scope. result );

 

Small Example of simple use of operators (switch button effect)

I. Page Structure

<Div id = "div1" class = "open1">
<Div id = "div2" class = "open2"> </div>
</Div>

Ii. Style

# Div1 {
Width: 170px;
Height: 100px;
Border-radius: 50px;
Position: relative;
}
# Div2 {
Width: 96px;
Height: 96px;
Border-radius: 48px;
Position: absolute;
Background: white;
Box-shadow: 0px 2px 4px rgba (0, 0, 0, 0.4 );
}
. Open1 {
Background: rgba (0,184, 0, 0.8 );
}
. Open2 {
Top: 1px;
Right: 0px;
}
. Close1 {
Background: rgba (255,255,255, 0.4 );
Border: 3px solid rgba (0, 0, 0, 0.15 );
Border-left: transparent;
}
. Close2 {
Left: 0px;
Top: 0px;
Border: 2px solid rgba (0.1, 0 );
}

Iii. Event Methods

Window. onload = function (){
Var div2 = document. getElementById ("div2 ");
Var div1 = document. getElementById ("div1 ");
Div2.onclick = function (){
Div1.className = (div1.className = "close1 ")? "Open1": "close1 ";
Div2.className = (div2.className = "close2 ")? "Open2": "close2 ";
}
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.