<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>注册</title>
<script src="./node_modules/angular/angular.js"></script>
</head>
<body ng-app="s1.app">
<div>
<div>
<label for="ipt_name">用户名</label>
<input ng-model="data.name" type="text" id="ipt_name">
<span ng-bind="data.errorMsg.name"></span>
</div>
<div>
<label for="ipt_password">密码</label>
<input ng-model="data.password" type="password" id="ipt_password">
</div>
<div>
<label for="ipt_age">年龄</label>
<input ng-model="data.age" type="number" id="ipt_age">
</div>
<div>
<label for="ipt_phone">手机</label>
<input ng-model="data.phone" type="tel" id="ipt_phone">
</div>
<div>
<button ng-click="actions.submit()">注册</button>
</div>
</div>
<script>
// app是application的缩写,application是应用程序的意思
var app = angular.module('s1.app', []);
app.run(function ($rootScope) {
// data是数据的意思
var data = $rootScope.data = {};
data.name = '';
data.password = '';
data.age = 0;
data.phone = '';
data.errorMsg = {}; // actions是行为的意思
var actions = $rootScope.actions = {};
actions.submit = function () {
var userinfo = {};
if(data.name == ''){
data.errorMsg.name = '用户名不能为空';
return;
}
userinfo.name = data.name;
userinfo.password = data.password;
userinfo.age = data.age;
userinfo.phone = data.phone;
// 从数据对象上拿到我们想要的数据,然后做提交(现在我们没有服务器,只是log一下)
console.log(userinfo);
}
}) </script>
</body>
</html>

使用angular.js获取form表单中的信息的更多相关文章

  1. JS获取form表单数据

    以下代码可放在一个js文件中,以便通用: //获取指定表单中指定标签对象 function getElements(formId, label) { var form = document.getEl ...

  2. JS 获取form表单的所有数据

    在HTML中用js获取通过GET.POST方法(就是在网址后加?a=b&c=d之类)传过来的表单值. 针对大家常用的获取表单方式,很多时候都是在重复的写一些代码,今天给大家贴出来的代码可以作为 ...

  3. 在 easyui中获取form表单中所有提交的数据 拼接到table列表中

    form表单===== <!-- 并用药品填写信息弹框 --> <div id="usingProdctMsgDiv" style="display: ...

  4. jquery获取form表单中的内容,并将表单内容更新到datagrid的一行

    //执行不刷新页面更新所修改的行 var arr = $('#patient_form').serializeArray();//将表单中的数据格式化成数组 var m = new Array(); ...

  5. (转载)php获取form表单中name相同的表单项

    (转载)http://hi.baidu.com/ruhyxowwzhbqszq/item/5fd9c8b9b594db47ba0e12a9 比如下面的表单: /*form.php*/ <form ...

  6. JS获取form表单所有属性值

    // 得到一个表单里的全部信息function getFormQueryString() { var frmID=document.forms[0]; var i,queryString=" ...

  7. js获取form表单所有数据

    代码如下: <script type="text/javascript"> // 获取指定form中的所有的<input><select>对象 ...

  8. JS获取form表单的所有输入值

    function getFormQueryString(frmID) { var frmID=document.getElementById(frmID); var i,queryString = & ...

  9. jquery获取form表单中的数据

    $(function() { $('#submit').click(function() { var d = {}; var t = $('form').serializeArray(); //t的值 ...

随机推荐

  1. Vue2 封装的 Quill 富文本编辑器组件 Vue-Quill-Editor

    1.安装 npm install vue-quill-editor --save 2.使用 import { quillEditor } from 'vue-quill-editor' 3.组件中 & ...

  2. react 基础篇 #2 create-react-app

    1. 介绍 在开发react应用时,应该没有人用传统的方法引入react的源文件(js),然后在html编辑吧. 大家都是用webpack + es6来结合react开发前端应用. 这个时候,我们可以 ...

  3. centos7网卡重命名为ethx格式

    参考:https://www.cnblogs.com/zyd112/p/8143464.html CentOS 7 使用 eth0 这样的传统名称,那么在安装启动(pxe)时,按Tab键在下方输入以下 ...

  4. PAT_A1148#Werewolf - Simple Version

    Source: PAT 1148 Werewolf - Simple Version (20 分) Description: Werewolf(狼人杀) is a game in which the ...

  5. JS 常用语法

    通常,通过 JavaScript,您需要操作 HTML 元素. 1.通过 id 找到 HTML 元素 2.通过标签名找到 HTML 元素 3.通过类名找到 HTML 元素 提示:通过类名查找 HTML ...

  6. Git 基础教程 之 --no-ff模式合并

    ①  创建并切换dev分支 ②  修改readme.txt,并add,commit ③  切回master ④  合并 git merge --no-ff -m “merge with no-ff”d ...

  7. Codeforces 816A/B

    A. Karen and Morning 传送门:http://codeforces.com/contest/816/problem/A 水题,参考程序如下: #include <stdio.h ...

  8. phpcms_完整版

    {pc:content action="category" catid="0" num="6" siteid="$siteid&q ...

  9. poj 3006水题打素数表

    #include<stdio.h> #include<string.h> #define N 1100000 int isprim[N],prime[N]; void ispr ...

  10. ExtJs之Ext.view.View

    要注意MODEL的定义和实例化的代码,注释掉的是老式的不兼容4.0以上的.而下面的定义才是新推荐的. 我网上可是查的了.是书上的代码老了. <!DOCTYPE html> <html ...