我有這樣動態形式不使用jQuery
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的文件我試圖讓上應該默認爲提交表單
$(document).on("click", "button.attend", function(e){
alert("hey");
e.preventDefault();
$.post("/file.php", { form: , method: "add" }, function() {
}, "json");
});
按鈕單擊事件創建的窗體
它不會提醒任何事情或阻止提交。 我試過用submit
和button.attend
來替換click
,它的形式是類名,但是什麼也沒有。有任何想法嗎?
爲什麼在文檔,而不是點擊事件的表單上的按鈕? –
因爲它位於facebox彈出框內。我用標準的$(button).on(「click」)來試試它......但它仍然沒有做任何事情 – Naterade
嗯,你做錯了。 –