gpt4 book ai didi

javascript - 使用 JQuery 或 Js (MVC) 禁用更新表单中的“保存”按钮

转载 作者:行者123 更新时间:2023-12-03 06:53:25 27 4
gpt4 key购买 nike

在更新中(因此每个文本框都会有值),我希望默认情况下禁用“保存”按钮,并在更改文本框值之一时启用它。使用 jQuery 或 Js。

@Html.TextBoxFor(model => model.FirstName, new { @class = "form-control" })
@Html.TextBoxFor(model => model.LastName, new { @class = "form-control" })
@Html.TextBoxFor(model => model.Address, new { @class = "form-control" })
@Html.TextBoxFor(model => model.Phone_No, new { @class = "form-control" })

<input type="submit" class="btn-mvc btn-mvc-green btn-mvc-fullwidth" value="Save Record" id="saveRecord">

最佳答案

确保添加对 jQuery >= 1.9 的引用,然后使用以下代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#saveRecord").prop('disabled', true);

$("#saveRecord").click(function () {

});

$(".form-control").on("change keyup paste",function () {
var text = $(this).val();
var textLength = text.length;

if(textLength > 0)
$("#saveRecord").prop('disabled', false);
else
$("#saveRecord").prop('disabled', true);
});
});
</script>

关于javascript - 使用 JQuery 或 Js (MVC) 禁用更新表单中的“保存”按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37399289/

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