Home  >  Article  >  Web Front-end  >  Checkbox selection changes state and change and click events in jquery

Checkbox selection changes state and change and click events in jquery

黄舟
黄舟Original
2017-06-27 09:20:018454browse

jqueryThree ways to judge checked:
.attr('checked); //See version 1.6+ and return: "checked" or "undefined"; 1.5 -Return: true or false
.prop('checked'); //16+:true/false
.is(':checked'); //All versions: true/false//Don't forget the colon Oh

There are several ways to write jquery assignment checked:
All jquery versions can be assigned like this:

// $("#cb1").attr("checked","checked");
// $("#cb1").attr("checked",true);

jquery1.6+:prop 4 types of assignments:

// $("#cb1″).prop("checked",true);//很简单就不说了哦
// $("#cb1″).prop({checked:true}); //
map
键值对
// $("#cb1″).prop("checked",function(){
return
 true;//
函数
返回true或false
});

//Remember there is this one: $("#cb1″).prop("checked","checked");

checkbox click and changeEvent

Method 1:

$("#ischange").change(function() { 
alert("checked"); 
});

Method 2:

$(function(){ 
if ($.browser.msie) { 
$('input:checkbox').click(function () { 
this.blur(); 
this.focus(); 
}); 
};

Method 3:

$("#ischange").change(function() { 
alert("checked"); 
}); 
});

Method 4:

$(function () {if ($.browser.msie) {$('input:checkbox').click(function () { this.blur(); this.focus(); }); }});

Method 5:

$(
document
).ready(function(){ 
$("testCheckbox").change(function() { 
alert("Option changed!"); 
}); 
});

The above is the detailed content of Checkbox selection changes state and change and click events 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