加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs ng-submit

发布时间:2020-12-17 08:54:54 所属栏目:安全 来源:网络整理
导读:介绍 http://docs.ngnice.com/api/ng/directive/ngSubmit 定义和用法 ng-submit 指令用于在表单提交后执行指定函数。 语法 form ng-submit = "expression" / form form 元素支持该属性。 参数值 expression 表单提交后函数将被调用,或者一个表达式将被执行

介绍

http://docs.ngnice.com/api/ng/directive/ngSubmit

定义和用法

ng-submit 指令用于在表单提交后执行指定函数。

语法

<form ng-submit="expression"></form>
<form> 元素支持该属性。

参数值

expression 表单提交后函数将被调用,或者一个表达式将被执行,表达式返回函数调用。

例子

<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Example - example-example32-production</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js"></script> </head> <body ng-app=""> <script> function Ctrl($scope) { $scope.list = []; $scope.text = 'hello'; $scope.submit = function() { if ($scope.text) { $scope.list.push(this.text); $scope.text = ''; } }; } </script> <form ng-submit="submit()" ng-controller="Ctrl"> Enter text and hit enter: <input type="text" ng-model="text"/> <input type="submit" /> <pre>list={{list}}</pre> </form> </body> </html>

当执行回车或点击提交input时,都会执行submit()方法,向list中添加数据。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读