$("td").click() 点击事件失效,求大神指导~~
jquery吧
全部回复
仅看楼主
level 1
<script type="text/javascript" language="javascript">
$(function() {
//背景格行
var row = 17;
//背景格列
var col = 14;
//创建内容表格
$("#start").click(function(){
var classNum = $(this).attr("class");
if(classNum == 1){
//创建背景格
createGrid(row,col);
$(this).attr("class", "2");
}
});
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////这里如果用$("#box").click()可以运行,用$("td").click()就什么效果都没有//////////////////////////////////
$("td").click(function() {
alert(1);
});
//创建背景格
function createGrid(row, col) {
var otr = {};
var otable = $("<table id='boxTable'></table>");
for ( var i = 0; i < row; i++) {
otr[i] = $("<tr id='boxTr'></tr>");
$(otable).append(otr[i]);
for ( var j = 0; j < col; j++) {
//td的class值不同,表示意思也不同 1:空 2:数字 3:有雷
otr[i].append($("<td id='boxTd' class='1' style='width: 18px; height: 18px; border: 1px solid red'></td>"));
}
}
$("#box").append(otable);
}
});
</script>
</head>
<body>
<div id="home">
<div id="dargs"></div>
<div id="titles">
<input type="button" id="start" class="1" value="start"/>
</div>
<div id="box">
</div>
</div>
</body>
2018年02月11日 05点02分 1
level 1
因为执行$("td").click()的时候 表格还未创建 所以$("td") 是空 所以失效了 你创建表格的时候 执行$("td").click()就可以了
2018年02月23日 06点02分 3
谢谢,你这答案算是给我又打开了一个思路了。万分感谢!
2018年03月17日 07点03分
1