国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

基于AngularJS實(shí)現(xiàn)表單驗(yàn)證功能

2019-11-19 15:57:27
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例為大家分享了AngularJS實(shí)現(xiàn)表單驗(yàn)證功能的具體代碼,供大家參考,具體內(nèi)容如下

<!--實(shí)例解析ng-app 指令定義了 AngularJS 應(yīng)用。ng-controller 指令定義了應(yīng)用控制器。ng-model 指令綁定了兩個(gè) input 元素到模型的 user 對(duì)象。formCtrl 函數(shù)設(shè)置了 master 對(duì)象的初始值,并定義了 reset() 方法。reset() 方法設(shè)置了 user 對(duì)象等于 master 對(duì)象。ng-click 指令調(diào)用了 reset() 方法,且在點(diǎn)擊按鈕時(shí)調(diào)用。novalidate 屬性在應(yīng)用中不是必須的,但是你需要在 AngularJS 表單中使用,用于重寫(xiě)標(biāo)準(zhǔn)的 HTML5 驗(yàn)證。 --><!DOCTYPE html><html ng-app="myApp"><head><meta charset="utf-8"><script src="js/angular.js"></script></head><body><!-- Checkbox(單選框)我們可以使用 ng-model 來(lái)綁定單選按鈕到你的應(yīng)用中。單選框使用同一個(gè) ng-model ,可以有不同的值,但只有被選中的單選按鈕的值會(huì)被使用--><form> 選擇一個(gè)選項(xiàng): <input type="radio" ng-model="myVar" value="dogs">Dogs <input type="radio" ng-model="myVar" value="tuts">Tutorials <input type="radio" ng-model="myVar" value="cars">Cars</form><div ng-switch="myVar"> <div ng-switch-when="dogs">   <h1>Dogs</h1>   <p>Welcome to a world of dogs.</p> </div> <div ng-switch-when="tuts">   <h1>Tutorials</h1>   <p>Learn from examples.</p> </div> <div ng-switch-when="cars">   <h1>Cars</h1>   <p>Read about cars.</p> </div></div><p>ng-switch 指令根據(jù)單選按鈕的選擇結(jié)果顯示或隱藏 HTML 區(qū)域。</p><br><br><br><br><!-- 下拉菜單使用 ng-model 指令可以將下拉菜單綁定到你的應(yīng)用中。ng-model 屬性的值為你在下拉菜單選中的選項(xiàng)--><form> 選擇一個(gè)選項(xiàng): <select ng-model="myVar2">  <option value="">  <option value="dogs">Dogs  <option value="tuts">Tutorials  <option value="cars">Cars </select></form><div ng-switch="myVar2"> <div ng-switch-when="dogs">   <h1>Dogs</h1>   <p>Welcome to a world of dogs.</p> </div> <div ng-switch-when="tuts">   <h1>Tutorials</h1>   <p>Learn from examples.</p> </div> <div ng-switch-when="cars">   <h1>Cars</h1>   <p>Read about cars.</p> </div></div><p>ng-switch 指令根據(jù)下拉菜單的選擇結(jié)果顯示或隱藏 HTML 區(qū)域。</p><br><br><br><br><!-- novalidate--><form action="xxx.do" novalidate>E-mail: <input type="email" name="user_email"><input type="submit"></form><p><strong>注意:</strong>在 Safari 和 Internet Explorer 9 及之前的版本中不支持 novalidate 屬性。這個(gè)屬性可以關(guān)閉瀏覽器默認(rèn)校驗(yàn)</p><br><br><br><br><!--Checkbox(復(fù)選框)checkbox 的值為 true 或 false,可以使用 ng-model 指令綁定,它的值可以用于應(yīng)用中--><div ng-app=""> <form>  選中復(fù)選框,顯示標(biāo)題:  <input type="checkbox" ng-model="myVar"> </form> <h1 ng-show="myVar">My Header</h1></div><p>標(biāo)題使用了 ng-show 指令,復(fù)選框選中后顯示 h1 標(biāo)簽內(nèi)容。</p><br><br><br><br><!-- HTML 表單HTML 表單通常與 HTML 控件同時(shí)存在以下 HTML input 元素被稱(chēng)為 HTML 控件:  input 元素  select 元素  button 元素  textarea 元素--><div ng-app="myApp" ng-controller="formCtrl"> <form novalidate>  First Name:<br>  <input type="text" ng-model="user.firstName"><br>  Last Name:<br>  <input type="text" ng-model="user.lastName">  <br><br>  <button ng-click="reset()">RESET</button> </form> <p>form = {{user}}</p> <p>master = {{master}}</p></div><script>var app = angular.module('myApp', []);app.controller('formCtrl', function($scope) {  $scope.master = {firstName: "John", lastName: "Doe"};  $scope.reset = function() {    $scope.user = angular.copy($scope.master);  };  $scope.reset();});</script></body></html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 五华县| 牟定县| 舞阳县| 安乡县| 宁国市| 措勤县| 莱芜市| 清流县| 铜川市| 尼玛县| 西乌珠穆沁旗| 永州市| 绥滨县| 霍邱县| 班玛县| 绥宁县| 德惠市| 财经| 新泰市| 青州市| 禄丰县| 四会市| 申扎县| 隆林| 汉阴县| 奉新县| 济源市| 宝山区| 朝阳区| 平湖市| 连州市| 清远市| 德清县| 西乡县| 铁力市| 都匀市| 无棣县| 出国| 同仁县| 姜堰市| 安龙县|