JavaScript

超轻量级php框架startmvc

angular+bootstrap的双向数据绑定实例

更新时间:2020-04-27 07:50:01 作者:startmvc
效果图:代码如下:<!doctypehtml><htmlng-app="UserInfoModule"><head><metacharset="utf-8">

效果图:

代码如下:


<!doctype html>
<html ng-app="UserInfoModule">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="external nofollow" >
<script src="js/angular-1.3.0.js"></script>
</head>
<body>
<div>
 <div class="panel panel-primary">
 <div class="panel-heading">
 <div class="panel-title">
 双向数据绑定
 </div>
 </div>
 <div class="panel-body">
 <div class="row">
 <div class="col-md-12">
 <form class="form-horizontal" role="form" ng-controller="UserInfoCtrl">
 <div class="form-group">
 <label class="col-md-2 control-label">邮箱:</label>
 <div class="col-md-10">
 <input type="email" class="form-control" placeholder="推荐使用126邮箱" ng-model="userInfo.email">
 </div>
 </div>
 <div class="form-group">
 <label class="col-md-2 control-label">密码:</label>
 <div class="col-md-10">
 <input type="password" class="form-control" placeholder="只能是数字、字母、下划线" ng-model="userInfo.password">
 </div>
 </div>
 <div class="form-group">
 <div class="col-md-offset-2 col-md-10">
 <div class="checkbox">
 <label>
 <input type="checkbox" ng-model="userInfo.autoLogin">自动登录
 </label>
 </div>
 </div>
 </div>
 <div class="form-group">
 <div class="col-md-offset-2 col-md-10">
 <button class="btn btn-default" ng-click="getFormData()">
 登录
 </button>
 </div>
 </div>
 </form>
 </div>
 </div>
 </div>
 </div>
</div>
</body>
<script>
 var UserInfoModule = angular.module('UserInfoModule',[]);
UserInfoModule.controller('UserInfoCtrl',['$scope',function($scope){
 $scope.userInfo={
 email:'1101867009@qq.com',
 password:'xu201133016',
 autoLogin:true
 };
 $scope.getFormData=function(){
 $scope.userInfo={
 email:'1101867009@qq.com',
 password:'xu201133016',
 autoLogin:true
 };
 };
 $scope.setFormData=function(){
 $scope.userInfo={
 email:'xu13071061935@163.com',
 password:'xu201133016',
 autoLogin:false
 }
 };
}])
</script>
</html>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持脚本之家!

angular双向数据绑定 angularjs 双向绑定