• Angular JS 学习之Bootstrap


    1.要使用Bootstrap框架,必须在<head>中加入链接:

    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">

    2.国内站点建议使用:

    <link rel="stylesheet" href="//apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.min.css">

    3.实例演示:

    <!DOCTYPE html>

    <html>

    <link rel="stylesheet" href="http://apps.bding.com/libs/bootstrap/3.3.4/css/bootstrap/.min.js">

    <script  src=http://apps.bding.com/libs/angular.js/1.4.6/angular.min.js></script>

    <body ng-app="myApp" ng-controller="userCtrl">  //为<body>元素定义一个控制器

    <div class="container">  //内容容器

    <h3>User</h3>

    <table class="table table-striped">  //带条纹背景的表格

      <thead><tr>

        <th>Edit</th>

        <th>First Name</th>

        <th>Last Name</th>

      </tr></thead>

      <tbody><tr ng-repeat="user in users">         //  循环users对象组,每个user对象放在<tr>元素中

        <td>

          <button class="btn" ng-click="editUser(user.id)">    //当点击<button>元素时调用函数editUser()

          <span class="glyphicon glyphicon-pencil"></span>&nbsp;&nbsp;Edit         //字形图标,铅笔图标

          </button>

        </td>

        <td>{{user.fName}}</td>

        <td>{{user.lName}}</td>

       </tr></tbody>

    </table>

    <hr>

    <button class="btn btn-success" ng-click="editUser('new')">

    <span class="glyphicon glyphicon-user"></span>Ctreate New User           //用户图标

    </button>

    <hr>

    <h3 ng-show="edit">Create New User:</h3>   //如果edit=“true”显示<h3>元素

    <h3 ng-hide="edit">Edit User:</h3>                //如果edit="true"隐藏<h3>元素

    <form class="form-horizontal">       //水平表格

    <div class="form-group">              //表单组

      <label class="col-sm-2 control-label">First Name:</label>    //控制器标签

      <div class="col-sm-10">

        <input type="text" ng-model="fName" ng-disabled="!edit" placeholder="First Name">   //为应用程序绑定<input>元素

      </div>

    </div>

    <div class="form-group">

      <label class="col-sm-2 control-label">Last Name:</label>     //跨越2列

      <div class="col-sm-10">               //跨越10列

        <input type="text" ng-model="lName" ng-disabled="!edit" placeholder="Last Name">

      </div>

    </div>

    <div class="form-group">

      <label class="col-sm-2 control-label">Password:</label>

      <div class="col-sm-10">

        <input type="password" ng-model="passw1" placeholder="Password">

      </div>

    </div>

    <div class="form-group">

      <label class="col-sm-2 control-label">Repeat:</label>

      <div class="col-sm-10">

        <input type="password" ng-model="passw2" placeholder="Repeat Password">

      </div>

    </div>

    </form>

    <hr>

    <button class="btn btn-success" ng-disabled="error || incomplete">    //如果发生错误或者ncomplete=true禁用<button>元素

      <span class="glyphicon glyphicon-save"></span>Save Changes

    </button>

    </div>

    <script src="myUsers.js"></script>

    </body>

    </html>

    4.Javascript代码:myUsers.js

    angular.module('myApp',[]).controller('userCtrl',function($scope){

    $scope.fName='';      //模型变量

    $scope.lName='';

    $scope.passw1='';

    $scope.passw2='';

    $scope.users=[          //模型变量用户数组

    {id:1,fName:'Hege',lName:'Pege'},

    {id:2,fName:'Kim',lName:'Pim'},

    {id:3,fName:'Sal',lName:'Smith'},

    {id:4,fName:'Jack',lName:'Jones'},

    {id:5,fName:'John',lName:'Doe'},

    {id:6,fName:'Peter',lName:'Pan'}

    ];

    $scope.edit=true;

    $scope.error=false;

    $scope.incomplete=false;

    $scope.editUser=function(id){

      if(id=='new'){

        $scope.edit=true;

        $scope.incomplete=true;

        $scope.fName='';

        $scope.lName='';

        }else{

        $scope.edit=false;

        $scope.fName=$scope.users[id-1].fName;

        $scope.lName=$scope.users[id-1].lName;

        }

    };

    $scope.$watch('passw1',function(){$scope.test();});     //监控模型变量

    $scope.$watch('passw2',function(){$scope.test();});

    $scope.$watch('fName',function(){$scope.test();});

    $scope.$watch('lName',function(){$scope.test();});

    $scope.test=function(){                                           //监控模型变量的错误和完整性

      if($scope.passw1!=$scope.passw2){

        $scope.error=true;

      }else{

        $scope.error=false;

      }

      $scope.incomplete=false;

      if($scope.edit && (!$scope.fName.length ||

      !$scope.lName.length ||

      !$scope.passw1.length || !$scope.passw2.length)){

        $scope.incomplete=true;

      }

    };

    });

  • 相关阅读:
    Flutter——去除字符串中的所有空格
    Flutter——类似淘口令复制弹窗(避免踩坑)
    Flutter——TextField输入框输入内容后,光标焦点保持在最后
    Flutter——TextField输入框光标焦点的获取和释放
    Flutter——设置text的最大长度
    Unity3D获得服务器时间/网络时间/后端时间/ServerTime,适合单机游戏使用
    Cocoapods问题汇总
    scrollToItem出错
    一种消除局部自适应对比度增强算法方块效应的方法
    实时和非实时调度策略测试总结
  • 原文地址:https://www.cnblogs.com/hqutcy/p/6114450.html
Copyright © 2020-2023  润新知