我想在复选框数组上激发一个事件。问题是,我相信,仅仅因为在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