如果在另一个字段中输入一些数据,如何使字段只读



这是W3Schools上的一个例子,但我应该如何处理文本字段?

<input type="checkbox" ng-model="all">
<br>
<input type="text" ng-readonly="all">

检查其他字段的模型值是否为空,然后启用只读。

var myApp = angular.module('myApp', []);
myApp.controller('FooController', ['$scope', function($scope) {
	  $scope.first = "";
	  $scope.second = "";
}]);
<script src="//unpkg.com/angular/angular.js"></script>
<body ng-app="myApp">
<div ng-controller="FooController">
<p>First Name:
<input ng-model="first"/>
</p>
<p>Last Name:
<input ng-model="second" ng-readonly="first !== ''"/>
</p>
</div>  
</body>

最新更新