如何使用angularjs實現文字框獲取焦點

魔豆發表於2016-01-30
<!DOCTYPE html>
<html ng-app="myApp">
<head>
    <title>angularjs-focus</title>
</head>
<body>
    <input type="text" set-Focus="">
    <script type="text/javascript" src="js/angular.min.js"></script>
    <script type="text/javascript">
    var myApp = angular.module('myApp',[]);
    myApp.directive('setFocus', function(){
          return function(scope, element){
            element[0].focus();
          };
    });
    </script>
</body>
</html>

 

相關文章