gpt4 book ai didi

javascript - 单击时禁用按钮但无法将参数传递给 Controller

转载 作者:行者123 更新时间:2023-12-03 02:04:15 25 4
gpt4 key购买 nike

我有一个按钮,单击该按钮后我想禁用它。

<input type="submit" value="Save" class="btn btn-default" name="submit" style="float: right; position: relative; right: -18px;" />

值“Save”需要从按钮传递到 Controller :

 public ActionResult EditCall(ModelCallDetails call, string submit)

但是,显然当我放置 OnClick 事件(例如禁用)时,参数不会推送到 Controller 。

是否确实将值传递给 Controller ​​,表单仍在发布模型信息。

最佳答案

使用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>

您可以在下面的代码片段中测试,当按钮变为禁用时,不会再调用提交事件。我只是将 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>

关于javascript - 单击时禁用按钮但无法将参数传递给 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49876289/

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