我在Razor TextBoxFor和PasswordFor,我想检查使用js,如果他们都充满了一些数据?如何检查是否PasswordFor为空
我的代码工作,但只有在有两个文本框的情况下。如何使它适用于PasswordFor?
@Html.TextBoxFor(m => m.Login, new {@class = "form-control", @id="tekst1"})
@Html.PasswordFor(m => m.Password, new {@class = "form-control", @id="tekst2"})
<script type="text/javascript">
function disableButtons() {
$("input[type='submit']").attr("disabled", true);
}
function enableButtons() {
$("input[type='submit']").attr("disabled", false);
}
$(document).ready(function() {
disableButtons();
var $textInputs = $('input[type="text"],textInputs');
$('input').on('change', function() {
var anyEmpty = $textInputs.filter(function() { return this.value == ""; }).length > 0;
if (!anyEmpty) {
enableButtons();
} else {
disableButtons();
}
});
});
</script>
请向我们展示所有相关代码(并正确格式化)。 – domsson
这不是纯粹的_html_。请修改您的标签。 – Optio
没有'textbox'这样的元素,所以你可以从你的选择器中删除它。然后,将'$ textInputs'的选择器更改为'$('input')'。密码字段上有'type =“password”',显然'type =“text”'不匹配。 –