我想在表格的单元格中输入2个元素数组的备用值。 我是通过以下代码来做到这一点的。
var arr= new Array("X","O");
var index=0;
$('td').click(function()
{
if($(this).html())
{
alert("Use empty slots");
}
else
{
var i=index % 2;
$(this).html("<b>"+ arr[i] +"</b>");
index++;
}
}
);
似乎没有调用click()内部的函数。 我的代码出了什么问题?
答案 0 :(得分:0)
如果您知道表格的ID或类
,请使用此选项$("#tableId").on("click", "td", function() {
//your code here
});