我想在複選框數組上激發一個事件。問題是,我相信,僅僅因爲在DOM第一次加載JavaScript事件處理程序後添加了這些複選框,事件處理程序在單擊它們時無法觸發這些新複選框。DOM加載後添加的複選框上的複選框單擊事件
這是我的代碼:
//this runs after the initial load of the page.
var fillSeries = function() {
$.getJSON('api/series', function(data) {
var result = '';
for(var i = 0; i < data.length; i++) {
//the first result is structure.
if(i == 0)
continue;
var tablerow = '<tr><td><input type="checkbox" class="showarray" value="'+ data[i].id +'" /> ' + data[i].title + '</td></tr>';
result += tablerow;
}
$('#series-table').append(result);
// remove the loading icon and text
$('#loading').remove();
});
}
// checkbox onclick listener
$('.showarray').click(function() {
console.log($(this).val());
});
我怎樣才能使事件火?
'$( '#系列表')上(。 'click','.showarray',function(){...})''再次!!!! – adeneo 2013-02-17 17:57:32