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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章