最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

AngularJS的表單使用詳解

 更新時(shí)間:2015年06月17日 10:16:30   投稿:goldensun  
這篇文章主要介紹了AngularJS的表單使用詳解,在JS原有的基礎(chǔ)上提供了更多與HTML交互的功能,需要的朋友可以參考下

 AngularJS提供豐富填寫表單和驗(yàn)證。我們可以用ng-click來處理AngularJS點(diǎn)擊按鈕事件,然后使用 $dirty 和 $invalid標(biāo)志做驗(yàn)證的方式。使用novalidate表單聲明禁止任何瀏覽器特定的驗(yàn)證。表單控件使用了大量的角活動(dòng)。讓我們快速瀏覽一下有關(guān)事件先。
事件

AngularJS提供可與HTML控件相關(guān)聯(lián)的多個(gè)事件。例如ng-click通常與按鈕相關(guān)聯(lián)。以下是AngularJS支持的事件。

  •     ng-click
  •     ng-dbl-click
  •     ng-mousedown
  •     ng-mouseup
  •     ng-mouseenter
  •     ng-mouseleave
  •     ng-mousemove
  •     ng-mouseover
  •     ng-keydown
  •     ng-keyup
  •     ng-keypress
  •     ng-change

ng-click

使用點(diǎn)擊一個(gè)按鈕的指令,表單重置數(shù)據(jù)。

<input name="firstname" type="text" ng-model="firstName" required>
<input name="lastname" type="text" ng-model="lastName" required>
<input name="email" type="email" ng-model="email" required>
<button ng-click="reset()">Reset</button>
<script>
  function studentController($scope) { 
   $scope.reset = function(){
     $scope.firstName = "Mahesh";
     $scope.lastName = "Parashar";
     $scope.email = "MaheshParashar@yiibai.com";
 }  
  $scope.reset();
}
</script>

驗(yàn)證數(shù)據(jù)

可使用下面跟蹤誤差。

  •     $dirty - 規(guī)定值已被改變。
  •     $invalid- 該值的狀態(tài)是無效的。
  •     $error- 指出確切的錯(cuò)誤。

例子

下面的例子將展示上述所有指令。
testAngularJS.html

<html>
<head>
<title>Angular JS Forms</title>
<style>
table, th , td {
 border: 1px solid grey;
 border-collapse: collapse;
 padding: 5px;
}
table tr:nth-child(odd) {
 background-color: #f2f2f2;
}
table tr:nth-child(even) {
 background-color: #ffffff;
}
</style>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app="" ng-controller="studentController">
<form name="studentForm" novalidate>
<table border="0">
<tr><td>Enter first name:</td><td><input name="firstname" type="text" ng-model="firstName" required>
  <span style="color:red" ng-show="studentForm.firstname.$dirty && studentForm.firstname.$invalid">
   <span ng-show="studentForm.firstname.$error.required">First Name is required.</span>
  </span>
</td></tr>
<tr><td>Enter last name: </td><td><input name="lastname" type="text" ng-model="lastName" required>
  <span style="color:red" ng-show="studentForm.lastname.$dirty && studentForm.lastname.$invalid">
   <span ng-show="studentForm.lastname.$error.required">Last Name is required.</span>
  </span>
</td></tr>
<tr><td>Email: </td><td><input name="email" type="email" ng-model="email" length="100" required>
<span style="color:red" ng-show="studentForm.email.$dirty && studentForm.email.$invalid">
   <span ng-show="studentForm.email.$error.required">Email is required.</span>
  <span ng-show="studentForm.email.$error.email">Invalid email address.</span>
  </span>
</td></tr>
<tr><td><button ng-click="reset()">Reset</button></td><td><button 
 ng-disabled="studentForm.firstname.$dirty && studentForm.firstname.$invalid ||
   studentForm.lastname.$dirty && studentForm.lastname.$invalid ||
   studentForm.email.$dirty && studentForm.email.$invalid"
 ng-click="submit()">Submit</button></td></tr>
</table>
</form>
</div>
<script>
function studentController($scope) { 
  $scope.reset = function(){
 $scope.firstName = "Mahesh";
 $scope.lastName = "Parashar";
 $scope.email = "MaheshParashar@yiibai.com";
  }  
  $scope.reset();
}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
</body>
</html>

輸出

在Web瀏覽器打開textAngularJS.html??吹浇Y(jié)果如下。

2015617100230750.png (715×347)

相關(guān)文章

  • AngularJS日期格式化常見操作實(shí)例分析

    AngularJS日期格式化常見操作實(shí)例分析

    這篇文章主要介紹了AngularJS日期格式化常見操作,結(jié)合實(shí)例形式分析了AngularJS日期格式化常用參數(shù)功能、設(shè)置與使用技巧,需要的朋友可以參考下
    2018-05-05
  • Angularjs實(shí)現(xiàn)多個(gè)頁面共享數(shù)據(jù)的方式

    Angularjs實(shí)現(xiàn)多個(gè)頁面共享數(shù)據(jù)的方式

    本文給大家介紹使用Angularjs實(shí)現(xiàn)多個(gè)頁面共享數(shù)據(jù)的方式,通過定義一個(gè)共享服務(wù)service來實(shí)現(xiàn)此功能,對(duì)angularjs共享數(shù)據(jù)相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)
    2016-03-03
  • 如何以Angular的姿勢打開Font-Awesome詳解

    如何以Angular的姿勢打開Font-Awesome詳解

    這篇文章主要給大家介紹了關(guān)于如何以Angular的姿勢打開Font-Awesome的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Angular具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-04-04
  • angular中使用路由和$location切換視圖

    angular中使用路由和$location切換視圖

    這篇文章主要介紹了angular中使用路由和$location切換視圖,需要的朋友可以參考下
    2015-01-01
  • AngularJS 中ui-view傳參的實(shí)例詳解

    AngularJS 中ui-view傳參的實(shí)例詳解

    這篇文章主要介紹了AngularJS 中ui-view傳參的實(shí)例詳解的相關(guān)資料,這里提供實(shí)例幫助大家學(xué)習(xí)理解這部分內(nèi)容,需要的朋友可以參考下
    2017-08-08
  • AngularJS中的$watch(),$digest()和$apply()區(qū)分

    AngularJS中的$watch(),$digest()和$apply()區(qū)分

    這篇文章主要介紹了AngularJS中的$watch(),$digest()和$apply()區(qū)分,感興趣的朋友可以參考一下
    2016-04-04
  • 詳解AngularJS中module模塊的導(dǎo)入導(dǎo)出

    詳解AngularJS中module模塊的導(dǎo)入導(dǎo)出

    本文給大家介紹angularjs中module模塊的導(dǎo)入導(dǎo)出,涉及到angularjs module相關(guān)知識(shí),對(duì)angularjs module感興趣的朋友一起看看吧
    2015-12-12
  • AngularJS向后端ASP.NET API控制器上傳文件

    AngularJS向后端ASP.NET API控制器上傳文件

    這篇文章主要介紹了AngularJS向后端ASP.NET API控制器上傳文件的相關(guān)資料,需要的朋友可以參考下
    2016-02-02
  • angular內(nèi)容投影詳解

    angular內(nèi)容投影詳解

    這篇文章主要為大家介紹了angular內(nèi)容投影,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-12-12
  • AngularJS中實(shí)現(xiàn)顯示或隱藏動(dòng)畫效果的方式總結(jié)

    AngularJS中實(shí)現(xiàn)顯示或隱藏動(dòng)畫效果的方式總結(jié)

    AngularJS 是一組用于創(chuàng)建單頁Web應(yīng)用的豐富框架,給構(gòu)建豐富交互地應(yīng)用帶來了所有功能,其中一項(xiàng)主要的特性是Angular對(duì)動(dòng)畫的支持。下面通過本文給大家介紹AngularJS中實(shí)現(xiàn)顯示或隱藏動(dòng)畫效果的方式總結(jié),對(duì)angularjs動(dòng)畫效果相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)
    2015-12-12

最新評(píng)論

嵩明县| 连江县| 霍州市| 建昌县| 连南| 苏尼特左旗| 昌乐县| 南涧| 兴隆县| 射洪县| 鹰潭市| 蒙阴县| 仙桃市| 井陉县| 巴彦县| 长沙市| 咸宁市| 容城县| 凤凰县| 五大连池市| 屏山县| 杭锦后旗| 牙克石市| 太谷县| 遂川县| 永仁县| 四子王旗| 克拉玛依市| 开远市| 镇雄县| 黔东| 台南县| 无棣县| 太湖县| 加查县| 北碚区| 明溪县| 德格县| 新沂市| 滦南县| 邹平县|