我正在使用Parsley验证表单。
我已经重复了很多StackOverflow问题。但对我没有用
问题是,一开始我有两个禁用的密码字段,并且将使用复选框启用它们:
$('#chk_change_pass').on('change', function() {
if ($(this).is(':checked')) {
$('[name=password]')
.prop('disabled', false);
}
else {
$('[name=password]')
.prop('disabled', true);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form data-parsley-validate>
<input type="checkbox" id="chk_change_pass">
<input type="password" name="password" data-parsley-excluded="[disabled]" disabled required>
<input type="submit">
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/parsley.js/2.8.1/parsley.min.js"></script>
在禁用删除后,也不排除在开始时没有出现
答案 0 :(得分:0)
您需要使用change
而不是ifChanged
来触发复选框更改
$('#chk_change_pass').on('change', function() {
if ($(this).is(':checked')) {
$('[name=password]')
.prop('disabled', false);
}
else {
$('[name=password]')
.prop('disabled', true);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form data-parsley-validate>
<input type="checkbox" id="chk_change_pass">
<input type="password" name="password" data-parsley-excluded="[disabled]" disabled >
<input type="submit">
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/parsley.js/2.8.1/parsley.min.js"></script>