In this plunk我有一个包含KendoSortable的指令。我想知道用户何时点击任何可排序的div,但未触发click事件。这段代码有什么问题?
HTML
<dir2></dir2>
的Javascript
var app = angular.module("app", [ "kendo.directives" ]);
app.directive('dir2', function() {
var directive = {};
directive.restrict = 'EA';
directive.template = '<div kendo-sortable="list" id="listid"></div>';
directive.link = function(scope, element, attrs) {
scope.$on("kendoWidgetCreated", function(event, widget){
if (widget === scope.list) {
$('#listid').append ( '<div class="item">11111111</div>');
$('#listid').append ( '<div class="item">22222222</div>');
$('#listid').append ( '<div class="item">33333333</div>');
}
});
$('.item').on( "click", function( event ){
alert('clicked');
console.log(event);
});
};
return directive;
});
答案 0 :(得分:0)
如果你的项目是动态生成的,那么
$('.item').on( "click", function( event ){
//yourcode
});
将无效,您需要调用DOM然后调用您正在侦听的对象。
$(document).on( "click", ".item", function( event ){
});