加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angularjs使用link为元素绑定响应事件

发布时间:2020-12-17 10:01:10 所属栏目:安全 来源:网络整理
导读:1、HTML源码 !doctype htmlhtml ng-app="MyModule"headmeta charset="utf-8"/headbodyhello/hello/bodyscript src="../framework/angular-1.3.0.14/angular.js"/scriptscript src="HelloAngularLink.js"/script/html 2、angularjs源码 var myModule = angula

1、HTML源码

<!doctype html>
<html ng-app="MyModule">
	<head>
		<meta charset="utf-8">
	</head>
	<body>
		<hello></hello>
	</body>
	<script src="../framework/angular-1.3.0.14/angular.js"></script>
	<script src="HelloAngularLink.js"></script>
</html>

2、angularjs源码

var myModule = angular.module("MyModule",[]);
myModule.directive("hello",function() {
    return {
        restrict: 'E',template: '<div>Hi everyone!</div>',replace: true,link: function(scope,el,attrs,controller) {
            //console.log("<hello>...link...");
            el.on("mouseenter",function() {
                console.log("鼠标进入...");
            });
        }
    }
});

3、执行效果

页面:

当鼠标移动到页面上后,console打出的日志:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读