时间:2021-01-07 11:28:57 | 栏目:AngularJS | 点击:次
本文实例为大家分享了AngularJS表单简单操作代码,供大家参考,具体内容如下
HTML正文:
<div ng-app="myApp" ng-controller="myCtrl"> <!-- novalidate:当提交表单时不对表单数据(输入)进行验证 --> <form novalidate> First Name:<input type="text" ng-model="user.firstName"><br> Last Name:<input type="text" ng-model="user.lastName"> <br><br> <button ng-click="reset()">RESET</button> </form> <p>form = {{user }}</p> <p><font color="red">initInfo = {{initInfo}}</font></p> </div>
Javascript操作代码:
var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.initInfo = {firstName:"squirrel", lastName:"Python"}; $scope.reset = function() { $scope.user = angular.copy($scope.initInfo); // user对象等于master对象:深复制 }; //JS扫描脚本时会自动调用reset方法进行输入框信息的初始化 $scope.reset(); });
效果: