【发布时间】:2017-07-13 16:14:11
【问题描述】:
我正在使用 jQuery 创建一个包含图像的表格。我的 js 代码如下所示:
$(document).ready(function() {
var korpusArray = new Array();
$.getJSON("file.js", function(data) {
var korpusId;
var korpusChooseTable = "<table id='TableKorpusGaleria'><tbody><tr>";
$.each(data, function(i, value) {
korpusArray.push(value.text);
strRemove = value.filename.replace("korpus/", "");
korpusChooseTable += '<td><p>'+value.title+'</p><p style="display:none;">'+value.id+'</p></br><img src="/korpus/thumbs/phoca_thumb_s_'+strRemove+'"></td>';
});
korpusChooseTable += '</tr></tbody></table>';
$("#korpusChoose").html(korpusChooseTable);
console.log(korpusArray.length);
console.log(data.length);
});
// after this I wanna click on table cell and do some function but
// it doesnt work. Can somebody tell me what I'm doing wrong?
$("#korpusChoose #TableKorpusGaleria tbody td").click(function() {
alert();
});
});
【问题讨论】:
-
生成的表格的html是什么样子的?
-
顺便说一句,有些浏览器不喜欢
alert(),坚持alert(1)或更好的console.log(前提是您的浏览器支持)。 -
是的,我试过了,用 $("#korpusChoose table tbody td").click(function(){ alert(); });
-
警报('helo');也不起作用/铬
-
格式很好,应该没有问题
标签: jquery json html-table click mouseevent