【发布时间】:2016-12-20 23:16:08
【问题描述】:
我想通过创建自定义指令来更改 mouseenter 和 mouseleave 事件上的表格行 <tr> 的 CSS:
<!DOCTYPE html>
<html ng-app="m1">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.7/angular.min.js"></script>
</head>
<body>
<table>
<custom_tr>
<td>Hello</td>
</custom_tr>
<custom_tr>
<td>Hi</td>
</custom_tr>
<custom_tr>
<td>Bye</td>
</custom_tr>
</table>
</body>
<script>
var m1 = angular.module("m1", []);
m1.directive('custom_tr', function()
{
var d={};
d.restrict = 'E';
d.link = function(scope, element, attr)
{
element.bind('mouseenter', function(){
element.css({'font-style': 'italic'});
});
element.bind('mouseleave', function(){
element.css({'font-style': 'normal'});
});
}
return d;
});
</script>
</html>
谁能解释为什么它不能使用解决方案?
【问题讨论】:
标签: javascript angularjs html-table angularjs-directive dom-events