提交我現在有一個登錄表單顯示如下:顯示裝載機MVC
+----------------------------------+
| |
| +----------+ |
| | E: | |
| | P: | |
| | SUBMIT | |
| +----------+ |
| LOADER |
| |
+----------------------------------+
表單定義:
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post))
{
@Html.AntiForgeryToken()
<form action="" id="test">
我的提交按鈕顯示如下:
<div>
<input type="submit" value="Log in" onclick="OpenSite();" />
<a>@Html.ActionLink("Forgot your password?","ForgotPassword","Account")</a>
</div>
加載程序:
<div class="loader" id="myLoader" style="display:none">Loading...</div>
隨着「OpenSite」功能:
<script>
function OpenSite() {
$('.loader').show();
$('#openPopup').click();
};
</script>
我怎麼能強迫此功能在提交表單之前執行,但是當我按下「Submit
」按鈕?
即:
+---------------+
User Fills form
+---------------+
||
\/
+---------------+
User Presses
submit
+---------------+
||
\/
+---------------+
Display loader
+---------------+
||
\/
+---------------+
Display popup
+---------------+
||
\/
+---------------+
Submit form
to controller
+---------------+
這意味着,儘管接下來的頁面加載「加載」動畫顯示。
這是如何實現的?
我嘗試添加一個alert("hello world");
到函數的開始,它執行的,但我的加載程序未顯示在所有:(
任何幫助,將不勝感激
我也曾嘗試:
$("#test").submit(function (event) {
$('#myLoader').show();
});
沒有運氣
您是否嘗試過在表單提交事件中顯示它? – filur 2014-11-25 10:08:04
就像@filur建議的一樣,你需要使用「onsubmit」事件 – Th0rndike 2014-11-25 10:14:18
已經嘗試過了,沒有成功。 – jbutler483 2014-11-25 10:15:45