0
在以下单击div的示例中,背景必须更改为黄色。没有发生,也没有给出错误。 Pl,解释为什么!单击后指示背景不变(通过事件绑定)
//module declaration
var app = angular.module("myApp",[]);
//controller declaration
app.controller('myCtrl',function($scope){
\t $scope.name = 'Peter';
});
//directive declaration
app.directive('myStudent', function(){
\t return{
\t \t template:"<div style='width:200px;height:200px;'>Hi my friend!</div>",
\t \t link: function(scope, elem, attrs){
\t \t \t elem.bind('click',function(){
\t \t \t \t elem.css("background","yellow");
\t \t \t });
\t \t }
\t }
});
<body ng-app="myApp" ng-controller="myCtrl">
{{name}}<br/>
<my-student></my-student>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular.min.js"></script>
</body>