AngularJS 中,可以透過 ng-submit 來判斷 form 裡面的 submit 來完成一些事情(前提是form不能用action的屬性,不然一樣會被送出)
<script> function AlbumCtrl($scope) { $scope.age = '13'; $scope.arr = []; $scope.submit = function() { $scope.arr.push($scope.age); }; } </script> <form ng-controller="AlbumCtrl" ng-submit="submit()"> <label>Age:</label> <input ng-model="age"> <input type="submit" id="submit" value="Submit"> {{arr}} </form>