[英]Disable button on click but cannot pass parameter to controller
我有一个按钮,单击后要禁用它。
<input type="submit" value="Save" class="btn btn-default" name="submit" style="float: right; position: relative; right: -18px;" />
值“保存”需要从按钮传递到控制器:
public ActionResult EditCall(ModelCallDetails call, string submit)
但是,很明显,当我放置诸如Disable之类的OnClick事件时,该参数未推送到控制器。
无论如何,实际上是否会将值传递给控制器,表单仍在发布模型信息。
使用onsubmit
事件。
范例:
<form action="" method="post" onsubmit="return submitForm(this);">
<input type="submit" value="Save" class="btn btn-default" name="submit" style="float: right; position: relative; right: -18px;" />
</form>
<script type="text/javascript">
function submitForm(th) {
th.submit.disabled = true;
return true;
}
</script>
您可以在下面的代码段中测试,当按钮变为禁用状态时,不再调用Submit事件。 我只将return true
更改为return false
因为我不应该发布到stackoverflow。 只是为了向您显示该事件的提交按钮设置为disabled=true
之后,该事件不再可调用。
<form action="" method="post" onsubmit="return submitForm(this);"> <input type="submit" value="Save" class="btn btn-default" name="submit" /> </form> <script type="text/javascript"> function submitForm(th) { th.submit.disabled = true; console.log("passed"); return false; } </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.