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

首頁 > 語言 > JavaScript > 正文

基于AngularJS實現表單驗證功能

2024-05-06 15:13:40
字體:
來源:轉載
供稿:網友

本文實例為大家分享了AngularJS實現表單驗證功能的具體代碼,供大家參考,具體內容如下

<!--實例解析ng-app 指令定義了 AngularJS 應用。ng-controller 指令定義了應用控制器。ng-model 指令綁定了兩個 input 元素到模型的 user 對象。formCtrl 函數設置了 master 對象的初始值,并定義了 reset() 方法。reset() 方法設置了 user 對象等于 master 對象。ng-click 指令調用了 reset() 方法,且在點擊按鈕時調用。novalidate 屬性在應用中不是必須的,但是你需要在 AngularJS 表單中使用,用于重寫標準的 HTML5 驗證。 --><!DOCTYPE html><html ng-app="myApp"><head><meta charset="utf-8"><script src="js/angular.js"></script></head><body><!-- Checkbox(單選框)我們可以使用 ng-model 來綁定單選按鈕到你的應用中。單選框使用同一個 ng-model ,可以有不同的值,但只有被選中的單選按鈕的值會被使用--><form> 選擇一個選項: <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 指令根據單選按鈕的選擇結果顯示或隱藏 HTML 區域。</p><br><br><br><br><!-- 下拉菜單使用 ng-model 指令可以將下拉菜單綁定到你的應用中。ng-model 屬性的值為你在下拉菜單選中的選項--><form> 選擇一個選項: <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 指令根據下拉菜單的選擇結果顯示或隱藏 HTML 區域。</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 屬性。這個屬性可以關閉瀏覽器默認校驗</p><br><br><br><br><!--Checkbox(復選框)checkbox 的值為 true 或 false,可以使用 ng-model 指令綁定,它的值可以用于應用中--><div ng-app=""> <form>  選中復選框,顯示標題:  <input type="checkbox" ng-model="myVar"> </form> <h1 ng-show="myVar">My Header</h1></div><p>標題使用了 ng-show 指令,復選框選中后顯示 h1 標簽內容。</p><br><br><br><br><!-- HTML 表單HTML 表單通常與 HTML 控件同時存在以下 HTML input 元素被稱為 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>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 应用必备| 桦川县| 平定县| 麻江县| 卓尼县| 河津市| 兴山县| 灌阳县| 红原县| 吴川市| 樟树市| 桦南县| 盐边县| 柘城县| 友谊县| 江达县| 迁安市| 夹江县| 肥东县| 潢川县| 兴山县| 海原县| 上思县| 根河市| 唐海县| 库尔勒市| 商城县| 含山县| 永春县| 凌源市| 西充县| 牡丹江市| 新疆| 永德县| 资阳市| 平罗县| 兴隆县| 清新县| 丹凤县| 曲靖市| 海阳市|