gpt4 book ai didi

angularjs - ng-disabled 在 AngularJS 1.4.8 中的提交按钮上不起作用

转载 作者:行者123 更新时间:2023-12-04 16:10:05 25 4
gpt4 key购买 nike

这是我的第一个 AngularJS 联系表单(AngularJS 的新手)。我已经阅读了很多关于这个问题的帖子并尝试了很多解决方案,但我无法理解。看起来很简单,但我很难过。

我想在填充所需的输入(电子邮件和评论)之前禁用“提交”按钮。

此外,电子邮件和评论错误消息会在页面加载时立即显示,而不是等待模糊显示。

这是正确的 js(我使用的脚本来自教程,我误解了):

angular.module('contForm', [])
.controller('contCtrl', function ($scope) {
$scope.user = {};
})

<form ng-app="contForm" ng-controller="contCtrl" name="mailForm" novalidate>
<input type="text" name="name" ng-model="user.name" size="31" maxlength="50"><br>

<input type="text" name="phone" ng-model="user.phone" size="31" maxlength="12"><br>

<span ng-show="mailForm.email.$touched && mailForm.email.$invalid">Please enter your email address. </span>

<input type="email" name="email" ng-model="user.email" size="31" maxlength="100" required><br>

<span ng-show="mailForm.contComments.$touched && mailForm.contComments.$invalid">Please enter your comments. </span>

<input type="text" name="contComments" ng-model="user.comments" required><br>

<input type="submit" name="subComments" value="SEND" ng-disabled="mailForm.$invalid">
</form>

最佳答案

I can't find that error, i think your source is not complete, i used cdn angularjs.

input.btn[disabled] {
background: red;
}
<!DOCTYPE html>
<html >
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>

<form ng-app="app" ng-controller="ctrl" name="mailForm" novalidate>
<input type="text" name="name" ng-model="user.name" size="31" maxlength="50"><br>

<input type="text" name="phone" ng-model="user.phone" size="31" maxlength="12"><br>

<span ng-show="mailForm.email.$touched && mailForm.email.$invalid">Please enter your email address. </span>

<input type="email" name="email" ng-model="user.email" size="31" maxlength="100" required><br>

<span ng-show="mailForm.contComments.$touched && mailForm.contComments.$invalid">Please enter your comments. </span>

<input type="text" name="contComments" ng-model="user.comments" required><br>

<input class="btn" type="submit" name="subComments" value="SEND" ng-disabled="mailForm.$invalid">
</form>


<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js"></script>
<script>
var app = angular.module("app", []);

app.controller("ctrl", function ($scope) {

});
</script>
</body>
</html>

关于angularjs - ng-disabled 在 AngularJS 1.4.8 中的提交按钮上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44081037/

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