jQuery: changing on mark checkbox
When you mark/unmark the ch开发者_运维技巧eckbox I want it to window.location = index.php?mark=1 if it's marked, and if you click and it gets unmarked it should be mark=0
$('input:checkbox').click(function(){
window.location='/index.php?mark=' + ($(this).attr('checked') ? 1 : 0);
});
Should do the trick, but note that means it's going to cause a page reload between checks.
EDIT or as William mentioned, you can bind to .change() as well.
EDITv2 Working example: http://www.jsfiddle.net/T5CaC/
You're looking for jQuery.change(). When the checkbox check if the checkbox is checked or not.
$('#someCheckbox').change(function() {
window.location.search = ("?mark=" + (+this.checked));
});
Something like this:
$('input#mycheckbox').change(function () {
if ($(this).attr("checked")) {
window.location = index.php?mark=1;
return;
}
window.location = index.php?mark=0;
});
Check Here
精彩评论