angularJs中ng-readonly和ng-disabled的区别

时间:2021-11-28 08:50:06

**ng-readonly:不能修改,但是可以提交数据
ng-disabled:不能修改,也不可以提交数据**

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="angular.min.js"></script>
</head>
<body>
<style>
input[readonly]{background: #f3f3f3;border:solid 1px #aaa;}
</style>
<div ng-app="module" ng-controller="ctrl">
<form action="exam.php" method="post">
<!--readonly数据可以提交-->
<input type="text" name="a" readonly="readonly" value="readonly"><br/>
<!--disabled数据不可以提交-->
<input type="text" name="b" disabled="disabled" value="disabled"><br/>
<input type="submit">
</form>
<!--如果有user.uid,mail不可编辑-->
年龄: <input type="text" ng-model="user.age"><br/>
邮箱: <input type="text" ng-model="user.mail" ng-readonly="user.uid">
</div>
<script>
var m = angular.module('module', []);
m.controller('ctrl', ['$scope', function ($scope) {
$scope.user = {age: 18, uid: 1, mail: '123323232@qq.com'}
}]);
</script>
</body>
</html>

exam.php

<?php
echo "<pre>";
print_r($_POST);