我有些困惑,爲什麼我的一些jQuery不工作。
這裏的例子證明: http://jsfiddle.net/FS34t/624/
正如你可以看到,點擊一個「盒子」將觸發警報。
但是,當我嘗試將相同的行爲實現到我自己的代碼中時,單擊「框」不會觸發。
function scroll(e) {
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
var $items = $(balls());
$items.imagesLoaded(function(){
$container
.masonry('reloadItems')
.append($items).masonry('appended', $items, true);
});
}
}
function balls(){
$iterator -= 1;
if($iterator < 0){
var $boxes = $('<div class="box">No more games!</div>');
$container.append($boxes).masonry('appended', $boxes, false);
return;
}
var $width = 9;
return (
'<div class="box" style="width:18%">'
+'<p>'+$test[$iterator][1][2]['name']+'</p>'
+'<img src="scripts/php/timthumb.php?src='+$test[$iterator][2]+'&q=100&w=300"/>' //Replace this with the one below when timthumb is whitelisted
+'<div id=boxBottom>'+Math.floor($test[$iterator][0]*100)+'%</div>'
+'</div>'
);
我不確定爲什麼
$(".box").click(function(event){
alert("TEST");
});
不會在這裏工作。 我唯一的猜測是,這是因爲在jsfiddle示例中,'boxes'是在HTML中聲明的,而這些是在.js中生成的?
您應該確保在創建元素後設置點擊處理程序_after_。 – 2012-07-11 02:59:09