gpt4 book ai didi

javascript - 当文本字段中未输入值时按钮保持事件状态

转载 作者:太空宇宙 更新时间:2023-11-04 15:42:14 24 4
gpt4 key购买 nike

我正在开发一个页面,我想在文本框中输入所有值之前禁用提交按钮,但是当页面加载时,提交按钮已经处于事件状态

.directive('passwordVerify', function() {
return {
restrict: 'A',
require: '?ngModel',
link: function(scope, elem, attrs, ngModel) {
scope.$watch(attrs.ngModel, function() {
if (scope.confirm_password === scope.user_password) {
scope.pw.confirm_password.$setValidity('passwordVerify', true);
scope.pw.user_password.$setValidity('passwordVerify', true);
} else if (scope.confirm_password !== scope.user_password) {
scope.pw.confirm_password.$setValidity('passwordVerify', false);
scope.pw.user_password.$setValidity('passwordVerify', false);
}
});
}
};
})

HTML

<div class="list">
<form id="create" name="pw" method="post">
<label class="item item-input item-stacked-label">
<span class="input-label">Username</span>
<input type="text" placeholder="kojobaah" ng-model="username" required>
</label>

<label for="password">New Password
<input type="password" name="user_password" ng-model="user_password" ng-required="confirm_password && !user-password" password-verify="confirm_pasword">
<p ng-show="pw.user_password.$error.passwordVerify">Passwords do not match</p>
<p ng-show="pw.user_password.$error.required">This field is required</p>
</label>
</p>
<p>
<label for="password">Confirm Password
<input type="password" name="confirm_password" ng-model="confirm_password" ng-required="user_password && !confirm_password" password-verify="user_password">
<p ng-show="pw.confirm_password.$error.passwordVerify">Passwords do not match</p>
<p ng-show="pw.confirm_password.$error.required">This field is required</p>
</label>
<br />
<p align="center"><button ng-disabled="create.$invalid" class="button button-balanced" ng-click="register()">Create Account</button></p>
</form>
</div>

最佳答案

在:

<button ng-disabled="pw.$invalid" class="button button-balanced" 
ng-click="register()">Create Account</button>

create.$invalid 更改为 pw.$invalid

使用名称form而不是id

关于javascript - 当文本字段中未输入值时按钮保持事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43784721/

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