gpt4 book ai didi

javascript - Attr disable 不会禁用我的按钮

转载 作者:行者123 更新时间:2023-11-30 08:34:00 27 4
gpt4 key购买 nike

我有以下错误:

我有一个脚本可以检查 2 个字段是否相同,但是“注册”按钮始终是可点击的,而在所有字段都达到应有状态之前它应该是不可点击的。

我的完整代码:

$(document).ready(function () {
$('#registerModel_MemberProperties_0__Value').keyup(function () {
checkpassword($('#registerModel_Password'), $(this));
});

$('#registerModel_Password').keyup(function () {
checkpassword($(this), $('#registerModel_MemberProperties_0__Value'));
});

$('#registerModel_MemberProperties_0__Value').prop("type", "password").addClass("form-control")
function checkpassword(password, confirmpassword) {
var button = $('#Registerbutton');
button.attr("disabled", false);
if ($(password).val() == $(confirmpassword).val()) {
button.attr("disabled", false);
} else {
button.attr("disabled", true);
}
}
});

我的禁用按钮代码:

button.attr("disabled", false);

添加的 HTML:

<div class="row">
<div class="col-sm-12">
<fieldset>
@Html.ValidationSummary("registerModel", true)
@Html.LabelFor(m => registerModel.Name)
@Html.TextBoxFor(m => registerModel.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(m => registerModel.Name)
<br />
@Html.LabelFor(m => registerModel.Email)
@Html.TextBoxFor(m => registerModel.Email, new { @class = "form-control" })
@Html.ValidationMessageFor(m => registerModel.Email)
<br />
@Html.LabelFor(m => registerModel.Password)
@Html.PasswordFor(m => registerModel.Password, new { @class = "form-control" })
@Html.ValidationMessageFor(m => registerModel.Password)
<br />
@if (registerModel.MemberProperties != null)
{
for (var i = 0; i < registerModel.MemberProperties.Count; i++)
{
@Html.LabelFor(m => registerModel.MemberProperties[i].Value, registerModel.MemberProperties[i].Name)

@Html.EditorFor(m => registerModel.MemberProperties[i].Value)
@Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
<br />
}
}
@Html.HiddenFor(m => registerModel.MemberTypeAlias)
@Html.HiddenFor(m => registerModel.RedirectUrl)
@Html.HiddenFor(m => registerModel.UsernameIsEmail)
<button class="btn btn-success" id="Registerbutton">Sign up</button>
</fieldset>
</div>
</div>

最佳答案

$('#Registerbutton').attr("disabled", "disabled");

working demo

关于javascript - Attr disable 不会禁用我的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33830087/

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