我正在创建一个显示一列复选框的 HTML 表单,单击提交,该事件将被 jQuery 函数拾取。但是,在检查 Firebug 网络面板中的函数后,我注意到即使我只单击一次按钮,该函数也会触发多次!知道为什么吗?
HTML:
echo "<form id='massHoursSubtraction'>";
echo "How many hours to subtract? <input type='text' name='hours'><br />";
$entries = 1;
while($row = mysql_fetch_array($members)) {
$studentID = $row['studentid'];
echo "<input type='checkbox' name='studentID[]' id='' value='$studentID'>$studentID";
echo "<br />";
$entries++;
}
echo "<input type='button' id='submitValues' value='Submit' onclick='javascript:getHours($entries);' />";
echo "</form>";
Javascript:
function getHours(numberOfEntries) {
$(document).ready(function() {
$("#submitValues").click(function(){
var str = $("#massHoursSubtraction").serialize();
alert("How many times?");
$.post("output.php", str);
});
});
}
这是 Firebug 网络面板的屏幕截图:http: //imgur.com/Z83s5fr
这是$_POST
字符串:hours=1&studentID%5B%5D=5112244