angularJS之link函数对元素事件绑定或属性的操作

<!doctype html>
<html lang="en" ng-app="myApp">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
<script src="http://apps.bdimg.com/libs/angular.js/1.3.9/angular.min.js"></script>
</head>
<body >
    <div><hello>22<hello></div>
</body>
<script>
    var myApp=angular.module('myApp',[]);
    myApp.directive('hello',function(){
    return {
        restrict:'AE',
        template:'<div>hello angularJS</div>',
        replace:true,
        link:function(scope,element,attrs,controller){
        console.log("hello angularjs");
        element.on('mouseenter',function(){
        console.log("link函数处理元素事件绑定或属性的操作");

        });
        element.on('mouseout',function(){
        console.log("鼠标离开事件");
        });
        }
    }
    });
</script>
</html>
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页