html
  • angularjs
  • 2016-09-01 11 views 1 likes 
    1

    に焦点を当てていない:角度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

    あなたの入力ボックスを選択するために、angular.elementを使用することができますし、()フォーカスを呼び出すことができます。以下のようなものを試してみてください::

    <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

    ボタンのクリック時にテキストボックスにフォーカスを当てたいと思っています。ここで提供したリンクは、マウスポインタがテキストボックスにフォーカスしたときにテキストボックスにフォーカスします。 –

    関連する問題