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

Angualrjs 表單驗(yàn)證的兩種方式(失去焦點(diǎn)驗(yàn)證和點(diǎn)擊提交驗(yàn)證)

 更新時(shí)間:2017年05月09日 11:30:17   作者:Manson_zh  
AngularJS提供了表單驗(yàn)證,但是驗(yàn)證的過程交互體驗(yàn)很不好,比如重設(shè)密碼,重復(fù)密碼的時(shí)候一鍵入就會(huì)提示密碼不正確?,F(xiàn)在小編給大家整理了兩種方法,需要的的朋友參考下吧

AngularJS提供了表單驗(yàn)證,但是驗(yàn)證的過程交互體驗(yàn)很不好,比如重設(shè)密碼,重復(fù)密碼的時(shí)候一鍵入就會(huì)提示密碼不正確,現(xiàn)整理了兩種方法,僅供借鑒。

一,點(diǎn)擊提交驗(yàn)證

<form action="" class="form-horizontal col-md-9" name="reset_pwd" ng-submit="resetPwd()">
  <div class="form-group">
    <label class="col-sm-2 control-label">密碼</label>
    <div class="col-sm-8">
      <input type="password" name="mycompwd" class="form-control" ng-model="mycompwd" placeholder="請(qǐng)輸入密碼">
    </div>
  </div>
  <div class="form-group">
    <label class="col-sm-2 control-label">重復(fù)密碼</label>
    <div class="col-sm-8">
      <input type="password" name="resetmycompwd" class="form-control" ng-model="resetmycompwd" placeholder="再次輸入密碼" required>
    </div>
    <span style="color:red" ng-show="mycompwd!=resetmycompwd && reset_pwd.resetmycompwd.$dirty && reset_pwd.submitted
    ">密碼不一致</span>
  </div>
  <div class="form-group">
    <button type="submit" class="btn btn-primary" >確認(rèn)</button>
    <button type="button" class="btn btn-default" ng-click="resetpwd_cancle()">取消</button>
  </div>
</form>

當(dāng)用戶試圖提交表單時(shí),你可以在作用域中捕獲到一個(gè)submitted值,然后對(duì)表單內(nèi)容進(jìn)行驗(yàn)證并顯示錯(cuò)誤信息。

JS代碼

$scope.submitted = false;
$scope.resetPwd = function(){
  console.log(666);
  if($scope.reset_pwd.$valid && $scope.mycompwd == $scope.resetmycompwd){
    console.log('重置成功,進(jìn)行其他操作');
  }else{
    $scope.reset_pwd.submitted = true;
  }
}

親測(cè)可用。

第二種失去焦點(diǎn)驗(yàn)證

<form action="" class="form-horizontal col-md-9" name="reset_pwd" ng-submit="resetPwd()">
  <div class="form-group">
    <label class="col-sm-2 control-label">密&nbsp&nbsp碼</label>
    <div class="col-sm-8">
      <input type="password" name="mycompwd" class="form-control" ng-model="mycompwd" placeholder="請(qǐng)輸入密碼">
    </div>
  </div>
  <div class="form-group">
    <label class="col-sm-2 control-label">重復(fù)密碼</label>
    <div class="col-sm-8">
      <input ng-focus type="password" name="resetmycompwd" class="form-control" ng-model="resetmycompwd" placeholder="再次輸入密碼" required>
    </div>
    <span style="color:red" ng-show="mycompwd!=resetmycompwd && reset_pwd.resetmycompwd.$dirty
      && !reset_pwd.resetmycompwd.$focused
    ">密碼不一致</span>
  </div>
  <div class="form-group">
    <button type="submit" class="btn btn-primary" >確認(rèn)</button>
    <button type="button" class="btn btn-default" ng-click="resetpwd_cancle()">取消</button>
  </div>
</form>

JS代碼

app.directive('ngFocus',[function(){
  var focusClass = 'ng-focused';
  return{
    restrict:'AE',
    require:'ngModel',
    link:function(scope,element,attrs,ctrl){
      ctrl.$focused = false;
      element.bind('focus',function(e){
        element.addClass(focusClass);
        scope.$apply(function(){
          ctrl.$focused = true;
        });
        element.bind('blur',function(e){
          element.removeClass(focusClass);
          scope.$apply(function(){
            ctrl.$focused = false;
          });
        });
      })
    }
  };
}]);

注意HTML標(biāo)紅的地方。正是區(qū)分兩種方法的關(guān)鍵。

以上所述是小編給大家介紹的Angualrjs 表單驗(yàn)證的兩種方式(失去焦點(diǎn)驗(yàn)證和點(diǎn)擊提交驗(yàn)證),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Angularjs中$http以post請(qǐng)求通過消息體傳遞參數(shù)的實(shí)現(xiàn)方法

    Angularjs中$http以post請(qǐng)求通過消息體傳遞參數(shù)的實(shí)現(xiàn)方法

    這篇文章主要介紹了Angularjs中$http以post請(qǐng)求通過消息體傳遞參數(shù)的方法,結(jié)合實(shí)例形式分析了$http使用post請(qǐng)求傳遞參數(shù)的相關(guān)設(shè)置與使用技巧,需要的朋友可以參考下
    2016-08-08
  • AngularJS實(shí)現(xiàn)使用路由切換視圖的方法

    AngularJS實(shí)現(xiàn)使用路由切換視圖的方法

    這篇文章主要介紹了AngularJS實(shí)現(xiàn)使用路由切換視圖的方法,結(jié)合學(xué)生信息管理系統(tǒng)為例分析了使用controllers.js控制器來切換視圖的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下
    2017-01-01
  • AngularJS HTML編譯器介紹

    AngularJS HTML編譯器介紹

    這篇文章主要介紹了AngularJS HTML編譯器介紹,AngularJS的HTML編譯器能讓瀏覽器識(shí)別新的HTML語法。它能讓你將行為關(guān)聯(lián)到HTML元素或者屬性上,甚至能讓你創(chuàng)造具有自定義行為的新元素,需要的朋友可以參考下
    2014-12-12
  • Angular事件之不同組件間傳遞數(shù)據(jù)的方法

    Angular事件之不同組件間傳遞數(shù)據(jù)的方法

    這篇文章主要介紹了Angular事件之不同組件間傳遞數(shù)據(jù)的方法,利用Angular Event在不同組件之間傳遞數(shù)據(jù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • AngularJS快速入門

    AngularJS快速入門

    本文通過幾個(gè)循序漸進(jìn)的例子,給大家詳細(xì)講解了如何快速入門AngularJS,十分的實(shí)用,這里推薦給大家,有需要的小伙伴可以參考下。
    2015-04-04
  • Angular跨字段驗(yàn)證器中如何直接調(diào)用其它獨(dú)立的驗(yàn)證器

    Angular跨字段驗(yàn)證器中如何直接調(diào)用其它獨(dú)立的驗(yàn)證器

    我們?cè)陂_發(fā)的時(shí)候都會(huì)用到表單,那么驗(yàn)證器就是必不可少的東西,這篇文章主要給大家介紹了關(guān)于在Angular跨字段驗(yàn)證器中如何直接調(diào)用其它獨(dú)立的驗(yàn)證器的相關(guān)資料,需要的朋友可以參考下
    2022-03-03
  • AngularJs Dependency Injection(DI,依賴注入)

    AngularJs Dependency Injection(DI,依賴注入)

    本文主要介紹AngularJs Dependency Injection,這里整理了詳細(xì)資料及示例代碼有興趣的小伙伴可以參考下
    2016-09-09
  • angular中如何綁定iframe中src的方法

    angular中如何綁定iframe中src的方法

    這篇文章主要介紹了angular中如何綁定iframe中src的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-02-02
  • Angularjs驗(yàn)證用戶輸入的字符串是否為日期時(shí)間

    Angularjs驗(yàn)證用戶輸入的字符串是否為日期時(shí)間

    這篇文章主要介紹了Angularjs驗(yàn)證用戶輸入的字符串是否為日期時(shí)間,需要的朋友可以參考下
    2017-06-06
  • angular2 ng2-file-upload上傳示例代碼

    angular2 ng2-file-upload上傳示例代碼

    這篇文章主要介紹了angular2 ng2-file-upload上傳示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-08-08

最新評(píng)論

西昌市| 北票市| 陈巴尔虎旗| 综艺| 宜昌市| 梅州市| 台东县| 永吉县| 大宁县| 鄯善县| 南昌县| 兴国县| 江西省| 利辛县| 襄樊市| 东宁县| 古浪县| 宜川县| 云阳县| 乐昌市| 黑龙江省| 镇赉县| 武安市| 大足县| 九寨沟县| 紫金县| 莱阳市| 沽源县| 沾化县| 疏附县| 青田县| 沾益县| 石狮市| 高尔夫| 句容市| 普宁市| 五家渠市| 新安县| 广安市| 尚义县| 东丰县|