我將綁定點擊事件綁定到動態創建的元素。這是我的動態元素創建方法。onclick方法不起作用
ajaxCall("/getItems","POST",data,function(result){
var element = $('.item').first();
$('#item-list-section').empty();
for(var i = 0; i < result.items.length; i++){
var clone = element.clone();
clone.attr("id", result.items[i].itemId);
clone.find('.item-price').html("<h4>25</h4>");
if(result.items[i].itemName.length > 20){
clone.find('.item-name').css('overflow','hidden');
clone.attr('title', result.items[i].itemName)
}
clone.find('.item-name').html("<h4>"+ result.items[i].itemName + "</h4>");
clone.on('click',function(){
showToolTip();
});
clone.draggable({
revert : false,
zIndex: 1,
containment: "window",
opacity: 0.5,
cursor: "move",
helper: function() { return $(this).clone().appendTo('body').show(); }
});
$('#item-list-section').append(clone);
}
});
這是點擊事件功能!
function showToolTip(){
$newDiv = $('<div></div>');
$newDiv.css("display", "none");
$newDiv.addClass('tooltip');
$newDiv.append('adfhadfhadfhadfh')
$newDiv.appendTo("body");
$newDiv.fadeIn().css(({ left: e.pageX, top: e.pageY }));
}
我用螢火蟲調試點,但它不會從點擊功能中斷!我綁定點擊事件的方式是錯誤的!與此
clone.on('click',function(){
:
凡'$ newDiv'分配? – andyb