gpt4 book ai didi

jquery - 如何在点击提交按钮后显示jquery消息

转载 作者:行者123 更新时间:2023-12-03 22:54:29 25 4
gpt4 key购买 nike

我是 jquery 新手,想了解如何在单击提交按钮后显示消息(例如,请以绿色等待或提交)。

请帮忙

最佳答案

单击提交按钮后,通常会将表单提交到服务器,并且所有客户端脚本执行都会停止。因此,除非您对表单进行 AJAX 化,否则它将无法工作。为了 AJAXify 您的表单,您可以附加到 submit事件并替换默认操作:

$(function() {
$('#theForm').submit(function() {
// show a hidden div to indicate progression
$('#someHiddenDiv').show();

// kick off AJAX
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function() {
// AJAX request finished, handle the results and hide progress
$('#someHiddenDiv').hide();
}
});
return false;
});
});

和你的标记:

<form id="theForm" action="/foo" method="post">
<input name="foo" type="text" />
<input type="submit" value="Go" />
</form>

<div id="someHiddenDiv" style="display: none;">Working...</div>

关于jquery - 如何在点击提交按钮后显示jquery消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3377468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com