Js中冒号的作用:
1,声明对象的成员;
2,switch语句的分支;
3, 三元表达式。
(1)声明对象的成员:
var Book={
Name:'法',
Price:100,
Discount:function(rate){
this.Price*=rate;
}
};
alert(Book.Price);
Book.Discount(0.8);
alert(Book.Price);
2.switch语句分支
var a = 2;
switch (a)
{
case 0:
alert('0');
break;
case 1:
alert('1');
break;
case 2:
alert('2');
break;
default:
alert('_');
}
3.三元表达式
var a = 2;
var b = 4;
var k = (a > b ? 1 : 2);