JQuery三元运算语法:

varvalue=条件?value1:value2;

解释:设置一个变量value,根据条件进行判断,如果条件为真,则设置value=value1,否则value=value2


实例:

<scriptsrc="js/jquery-3.1.1.js"></script><scripttype="text/javascript">functioncheckAll(){$(':checkbox').prop('checked',true);}functioncancleall(){$(':checkbox').prop('checked',false);}</script><scripttype="text/javascript">functionreverseAll(){$(':checkbox').each(function(){//if(this.checked){//this.checked=false;//}else{//this.checked=true;//}//if($(this).prop('checked')){//$(this).prop('checked',false);//}else{//$(this).prop('checked',true);//}varv=$(this).prop('checked')?false:true;$(this).prop('checked',v);})}</script>

prop属性:

$(this).prop('checked'):表示获取checked属性的值,

$(this).prop('checked',true/false):表示设置checked属性的值为true/false。

prop常用语checked和selected属性

this: 表示DOM对象,$(this)表示JQuery对象,只有JQuery对象才能使用JQuery方法。