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>
发布了75 篇原创文章 · 获赞 5 · 访问量 7万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章