我有这样创建的表格
foreach($class_pool_result["data"] as $pool) {
$html[] = "<form action='/dashboard/attend' method='post' class='form_attend'>";
$html[] = "<input type='hidden' name='pool' value='" . $Encryption->encrypt(urlencode($pool["id"])) . "' />";
$html[] = "<input type='hidden' name='class' value='" . $Encryption->encrypt(urlencode($class["data"]["id"])) . "' />";
$html[] = "<table>";
$html[] = "<tr><td width='150'>" . $pool["plan_name"] . "</td><td><button class='attend'>Attend</button></td><td align='left'> <span style='color:#FF3902'>" . $pool["class_count"] . "</span> <small>classe(s) left</small></td></tr>";
$html[] = "</table>";
$html[] = "</form>";
}
然后在我的 jquery 文件中,我尝试在按钮上获取 click 事件,该按钮应该默认提交表单
$(document).on("click", "button.attend", function(e){
alert("hey");
e.preventDefault();
$.post("/file.php", { form: , method: "add" }, function() {
}, "json");
});
它不会提醒任何东西或阻止提交。我尝试用表单类名替换和替换,但click
没有submit
。button.attend
有任何想法吗?