2016-09-01 4 views
1

수 없습니다 버튼 클릭에 초점을하지 : 당신은 당신의 입력 상자를 선택 angular.element를 사용하여 초점을 호출 할 수 있습니다각도 JS 텍스트 상자는 버튼 클릭에 텍스트 상자에 초점을

<html ng-app="CommonApp"> 
<head> 
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
</head> 
<body ng-controller="HeadCtrl" ng-init='username=""'> 
    <input id="UserName" type="text" class="login_boxdecor" ng-model="username" /> 
    <div class="login_btn_outer"> 
     <div class="login_btn_outer2" ng-click="cLgn();"> 
      <a class="btn">Login</a> 
     </div> 
    </div> 
</body> 
</html> 
var myApp = angular.module('CommonApp', []); 
    myApp.controller('HeadCtrl', function($scope){ 
     $scope.cLgn= function(){ 
      if($scope.username.trim().length==0) 
      { 
       //Here How to focus my textbox 
      } 
     }; 
    }); 

답변

1
<html ng-app="CommonApp"> 
<head> 
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
</head> 
<body ng-controller="HeadCtrl" ng-init='username=""'> 
    <input id="UserName" type="text" class="login_boxdecor" ng-model="username" /> 
    <div class="login_btn_outer"> 
     <div class="login_btn_outer2" ng-click="cLgn();"> 
      <a class="btn">Login</a> 
     </div> 
    </div> 
</body> 
</html> 
var myApp = angular.module('CommonApp', []); 
    myApp.controller('HeadCtrl', function($scope){ 
     $scope.cLgn= function(){ 
      if($scope.username.trim().length==0) 
      { 
       document.getElementById("UserName").focus(); 
      } 
     }; 
    }); 
0

(). 아래 ::

<html ng-app="CommonApp"> 
<head> 
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
</head> 
<body ng-controller="HeadCtrl" ng-init='username=""'> 
    <input id="UserName" type="text" class="login_boxdecor" ng-model="username"/> 
    <div class="login_btn_outer"> 
     <div class="login_btn_outer2" ng-click="cLgn();"> 
      <a class="btn">Login</a> 
     </div> 
    </div> 
</body> 
</html> 
var myApp = angular.module('CommonApp', []); 
    myApp.controller('HeadCtrl', function($scope){ 
     $scope.focusText =false; 
     $scope.cLgn= function(){ 
      if($scope.username.trim().length==0) 
      { 
       angular.element("#UserName").focus(); 
      } 
     }; 
    }); 
+0

@Rahul 비슷한 시도 : 그것의 –

+0

cLgn()가 호출지고 작동하지 않음을 ?? 확인할 수 있습니까? 실행 코드보기 @ http://jsfiddle.net/deathhell/UTn5y/2/ – Ruhul

+0

버튼 클릭에 내 텍스트 상자를 집중시키고 싶습니다. 여기에서 제공 한 링크는 마우스 포인터가 텍스트 상자에 포커스를 맞추면 텍스트 상자에 집중합니다. –

관련 문제