gpt4 book ai didi

c# - 澄清暂时禁用提交按钮几秒钟,然后重新启用它?

转载 作者:行者123 更新时间:2023-11-28 09:06:50 25 4
gpt4 key购买 nike

这与提出的另一个问题类似,但表单不会提交。

基本上,我在这里尝试实现的是,一旦用户单击“提交”btn,该btn就会被禁用,直到页面重定向,以避免用户多次单击提交btn。

用户重定向到的页面将不会显示表单中的信息。在我介绍禁用和启用功能之前,它确实可以正常工作。

提供的代码确实禁用了 btn,甚至将文本更改为“正在提交”,但不会重定向到摘要页面,甚至当我通过选项卡导航到摘要页面时,信息也不存在。非常感谢任何帮助...

表单代码......

  <div class="portlet-body form">
<!-- BEGIN FORM-->
@using (Html.BeginForm("RequestAppointment", "Appointment", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", id= "apptReqForm" }))
{


@Html.AntiForgeryToken()
@Html.ValidationSummary(false, string.Empty, new { @class = "alert alert-error" })

<div class="control-group">
<label class="control-label">Healthcare Professional</label>
<div class="controls">
@Html.DropDownListFor(m => m.RequestedUserID, Model.Hcps, string.Empty)

</div>

</div>
<div class="control-group">
<label class="control-label">@Html.LabelFor(m => m.RequestedDateTime)</label>
<div class="controls">
<div class="input-append" id="ui_date_picker_trigger">
@Html.EditorFor(m => m.RequestedDateTime)
<span class="add-on"><i class="icon-calendar"></i></span>
</div>
</div>
</div>

<div class="control-group">
<label class="control-label">@Html.LabelFor(m => m.SelectedTime, "Time")</label>
<div class="controls">
<div id="timeSlotID" data-request-url="@Url.Action("LoadTimeslots")">
<select id="SelectedTime" name="SelectedTime"></select>
</div>
</div>
</div>

<div class="control-group">
<label class="control-label">@Html.LabelFor(m => m.AdditionalNotes)</label>
<div class="controls">
@Html.TextAreaFor(m => m.AdditionalNotes, new { @class = "span6 m-wrap", rows = 3 })
<span class="help-block m-wrap">In the event the selected time you have chosen is not available, please state above if your booking time is flexible.</span>
</div>
</div>

<div class="form-actions">
<button type="submit" class= "btn blue" id="submit" onclick="disable();"><i class="icon-ok"></i>Submit</button>
<button type="button" class="btn" onclick="location.href='RequestedAppointments'">Cancel</button>

</div>
}
</div>

<div class="form-actions">
<button type="submit" class= "btn blue" id="submit" onclick="disable();"><i class="icon-ok"></i>Submit</button>

<script>

function disable() {
x = document.getElementById("submit");
x.disabled = true;
x.textContent = "Submitting...";
document.getElementById("apptReqForm").submit();
setTimeout(enable, 5000);
}

function enable() {
x = document.getElementById("submit");
x.disabled = false;
x.textContent = " Submit";
}
</script>

最佳答案

您需要更改脚本才能执行以下操作:

function disable() {
x = document.getElementById("submit");
x.form.submit();
x.disabled = true;
x.textContent = "Submitting...";
setTimeout(enable, 5000);
}

function enable() {
x = document.getElementById("submit");
x.disabled = false;
x.textContent = " Submit";
}

然而,禁用该按钮可能会导致回发失败。

尝试查看这个解决方案(它使用 jQuery) Disable button after clicking once

关于c# - 澄清暂时禁用提交按钮几秒钟,然后重新启用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16936854/

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