将焦点设置在输入元素上

时间:2014-07-03 09:07:31

标签: angularjs

在以下AngularJS代码中:

<!doctype html>
<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js" ></script>
  </head>
    <script type="text/javascript">
      var myApp = angular.module('myApp', []);

      myApp.controller('MainCtrl', ['$scope', function ($scope) {
    }]);

  </script>
  <body>
    <div ng-app="myApp">
      <div ng-controller="MainCtrl">
        <script>
          function Ctrl($scope) {
            $scope.name = 'Whirled';
          }
        </script>
        <div ng-controller="Ctrl">
          <input type="text" ng-model="name" ng-focus=""><br>
          <input type="text" ng-model="place"><br>
        </div>
      </div>
    </div>
  </body>
</html>

我想将焦点放在第一个输入元素上。在angular.org上没有这样的例子,上面的代码不起作用。你如何使用ng-focus?该指令是否甚至存在?

0 个答案:

没有答案