1、angularjs版本:
<form class="login-form">
<h3 class="form-title">登录</h3>
<!--<div class="alert alert-danger display-block" data-ng-if="loginSpace.loginwaring">
<button class="close" data-close="alert" data-ng-click="closeLoginwaring()"></button>
<span>{{loginSpace.loginwaring_text}}</span>
</div>-->
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">用户名</label>
<input class="form-control form-control-solid placeholder-no-fix" type="text" data-ng-focus="setFocus()" data-ng-change="setChange()" autocomplete="off" placeholder="用户名" name="username" data-ng-model="loginSpace.name" />
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">密码</label>
<input class="form-control form-control-solid placeholder-no-fix" type="password" data-ng-focus="setFocus()" data-ng-change="setChange()" autocomplete="off" placeholder="密码" name="password" data-ng-model="loginSpace.pass" />
</div>
<div class="form-group">
<button type="button" class="btn btn-success" data-ng-click="login()" style="width: 100%;height: 43px;font-size: 16px;">登录</button>
</div>
</form>
$scope.setFocus = function(){
$scope.loginSpace.loginwaring = false;
$scope.loginSpace.loginwaring_text = "";
};
$scope.setChange = function(){
$scope.loginSpace.loginwaring = false;
$scope.loginSpace.loginwaring_text = "";
};
2、angular版本(本人代码用的angular6):
<form class="form-horizontal" id="userLogin" role="form" [formGroup]="formData">
<h3 class="form-title">登录</h3>
<div class="alert alert-danger display-block" *ngIf="loginwaring">
<button class="close" data-close="alert" (click)="login()"></button>
<span>{{loginwaring_text}}</span>
</div>
<div class="form-group">
<input class="form-control" type="text" autocomplete="off" placeholder="Username" formControlName="username" (keydown)="keydown($event)" (focus)="inputfocus($event)" (ngModelChange)="inputchange($event)"/>
</div>
<div class="form-group">
<input class="form-control " type="password" autocomplete="off" placeholder="Password" formControlName="password" (keydown)="keydown($event)" (focus)="inputfocus($event)" (ngModelChange)="inputchange($event)"/>
</div>
<div class="form-group">
<button type="button" class="btn green-haze" (click)="login()" style="width: 100%;height: 43px;font-size: 16px;">登录 </button>
</div>
</form>
inputfocus(e: any): void {//焦点
this.loginwaring = false;
this.loginwaring_text = "";
}
inputchange(e: any): void {//值改变,通过键盘改变焦点和登录时使用
this.loginwaring = false;
this.loginwaring_text = "";
}