当你勾选/取消标记复选框我希望它为window.location = index.php?mark = 1如果已标记,如果你点击它并且没有标记它应该是mark = 0
答案 0 :(得分:2)
$('input:checkbox').click(function(){
window.location='/index.php?mark=' + ($(this).attr('checked') ? 1 : 0);
});
应该这样做,但请注意,这意味着它会导致检查之间的页面重新加载。
编辑或提及William,您也可以绑定到.change()。
EDITv2 工作示例:http://www.jsfiddle.net/T5CaC/
答案 1 :(得分:0)
您正在寻找jQuery.change()。当复选框检查是否选中了复选框时。
答案 2 :(得分:0)
$('#someCheckbox').change(function() {
window.location.search = ("?mark=" + (+this.checked));
});
答案 3 :(得分:0)
这样的事情:
$('input#mycheckbox').change(function () {
if ($(this).attr("checked")) {
window.location = index.php?mark=1;
return;
}
window.location = index.php?mark=0;
});