selecting multiple checkbox in jquery
I wrote a jquery code to send values to a php file
$('#def_formSubmit').live("click",function(){
var query_string = '';
$("input[@type='checkbox'][@name='assotop']").each(
function()
{
if(this.checked)
{
query_string += "&assotop[]=" + this.value;
}
});
var def_tags = $("#tags").val();
var dataString = 'def_tags='+ def_tags + query_string ;
$.ajax({
type: 'POST',
url: 'post.php',
data: dataString,
cache: false,
beforeSend: function() {
$("#QRresult").html(&quo开发者_如何学Ct;<img src='images/loading.gif' />");
},
success: function(data5) {
$("#QRresult").html(data5);
}
});
return false;
});
But it does not work and does not sendi checkbox values to my php file.
I think this way of getting checkbox values is a old approach and not working for jquery 1.4.
Remove the @
from your selector. This changed as of 1.3
$("input[@type='checkbox'][@name='assotop']").each(
should be:
$("input[type='checkbox'][name='assotop']").each(
You could also do:
$("input:checkbox[name='assotop']").each(
EDIT: Added input
to the selector as noted by @lonesomeday.
EDIT: I guess I'd use the one with input[type='checkbox']
so that querySelectorAll
will be used in browsers that support it.
Try this code:
$(document).ready(function(){
$("#selectAll").change(function(){
$(".sports").prop('checked', ($(this).is(':checked')));
});
$(".sports").change(function(){
$("#selectAll").prop('checked', false);
});
});
精彩评论