我遇到以下错误:
我有一个脚本可以检查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>
答案 0 :(得分:1)
button.attr('disabled','disabled');
将完成这项工作。如果你想删除禁用,button.removeAttr('disabled');
将会解决问题。
答案 1 :(得分:1)
答案 2 :(得分:1)
使用.prop()代替.attr()
$('#Registerbutton').prop('disabled', true);
或
button.prop('disabled', true);
答案 3 :(得分:1)
$('#Registerbutton').attr("disabled", "disabled");
答案 4 :(得分:1)
好吧我用这个修好了:
$('#Registerbutton').attr("disabled", "disabled");
我需要做的是在我的
上操作按钮$(document).ready(function () {
然后它奏效了! 谢谢你的帮助!