如何在沒有頁面刷新的情況下將jQuery中的變量傳遞給PHP?當我點擊一個複選框時,我想將一個變量從jQuery傳遞給PHP。我也使用formdialog。如何將jQuery變量傳遞給PHP變量?
我的PHP代碼
<?php
echo "<input name='opendialog' type='checkbox' class='opendialog' onclick='countChecked()' value=".$taskid." ?>" /> </td>"
?>
我的javascript代碼
function countChecked() {
var n = $("input:checked").length;
var allVals = [];
$('input:checkbox:checked').each(function() {
allVals.push($(this).val());
});
$('.sel').text(allVals+' ');
$('.select1').val(allVals);
alert(allVals);
<?php $taskidj=$rowtask['taskID'];
// echo "aaa...".$rowtask['taskID']; ?>
}
$(":checkbox").click(countChecked);
// my jquery code
$('.mydialog').dialog({
bgiframe: true,
autoOpen: false,
modal: true,
width: 700,
height:500,
resizable: false,
open: function(){closedialog = 1;$(document).bind('click', overlayclickclose);},
focus: function(){closedialog = 0;},
close: function(){$(document).unbind('click');},
buttons: {
Submit: function(){
var bValid = true;
// allFields.removeClass("ui-state-error");
// bValid = bValid && checkLength(name, "username", 3, 16);
// bValid = bValid && checkRegexp(name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter.");
if (bValid) {
processDetails();
return false;
}
},
Cancel: function() {
$(this).dialog("close");
$('input[name=opendialog]').attr('checked', false);
}
}
});
$('.opendialog').click(function() {
$('.mydialog').dialog('open');
closedialog = 0;
});
可能重複的[如何使用jQuery POST將變量從JavaScript傳遞到PHP](http://stackoverflow.com/questions/2376913/how-to-pass-variable-from-javascript- to-php-using-jquery-post) – deceze 2011-03-05 06:12:21