我有一个表格。我想使用 jquery 添加事件处理程序。
$("form").submit(function blah() {
$.post('ping-me-please.php', params, function (response) {
// only submit the form once this goes through!
});
}
我怎样才能做到这一点?
最佳答案
像这样:
$("form").submit(function (e) {
var form = $(this);
if (!form.data('pinged')) {
e.preventDefault(); // Cancel the submit
$.post('ping-me-please.php', params, function (response) {
// only submit the form once this goes through!
// First we set the data, then we trigger the submit again.
form.data('pinged', true).submit();
});
}
}
关于javascript - 添加 form.submit 事件以确保在提交表单之前发布?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3682414/