Home > Web Front-end > JS Tutorial > body text

Checkbox selection changes state and change and click events in jquery

黄舟
Release: 2017-06-27 09:20:01
Original
8505 people have browsed it

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);
Copy after login

jquery1.6+:prop 4 types of assignments:

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

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

checkbox click and changeEvent

Method 1:

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

Method 2:

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

Method 3:

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

Method 4:

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

Method 5:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template