AngularJS ng-submit 指令
AngularJS 實例
表單提交後執行函數:
< body ng-app= "myApp" ng-controller= "myCtrl" >
< form ng-submit= "myFunc()" >
< input type= "text" >
< input type= "submit" >
< /form >
< p > {{myTxt}} < /p >
< script >
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.myTxt = "你還沒有點擊提交!";
$scope.myFunc = function () {
$scope.myTxt = "你點擊了提交!";
}
});
< /script >
< /body >
< form ng-submit= "myFunc()" >
< input type= "text" >
< input type= "submit" >
< /form >
< p > {{myTxt}} < /p >
< script >
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.myTxt = "你還沒有點擊提交!";
$scope.myFunc = function () {
$scope.myTxt = "你點擊了提交!";
}
});
< /script >
< /body >
嘗試一下»
定義和用法
ng-submit指令用於在表單提交後執行指定函數。
語法
< form ng-submit= " expression " > < /form >
<form> 元素支持該屬性。
參數值
值 | 描述 |
---|---|
expression | 表單提交後函數將被調用,或者一個表達式將被執行,表達式返回函數調用。 |