【发布时间】:2014-01-12 12:44:34
【问题描述】:
代码:
<script>
$(document).ready(function () {
$('#lifegrid tr td').click(function () {
$(this).addClass('selected');
});
$('#animatebutton').click(function () {
$(this).addClass('green');
animate();
});
function animate() {
var cell = [];
for (var x = 0; x < 16; x++) {
cell[y] = [];
for (var y = 0; y < 8; y++) {
if ($('#' + x + ',' + y).hasClass('selected')) {
cell[x,y] = 'alive';
console.log( x + "," + y + " is alive")
} else {
cell[x,y] = 'dead';
console.log( x + "," + y + " is dead")
}
}
}
}
});
</script>
我的代码还包含一个 <table> 和 <td> 元素,所有这些元素的 id 格式为“x,y”。示例:id="4,12"。
此代码仅返回“<coordinate> 已死”,无论该元素是否已分配“选定”类。为什么?
【问题讨论】:
-
所以你的选择器看起来像
$('#1,2')?2不是有效标签,也不是任何其他数字。 -
你也可以分享html吗
标签: javascript jquery html css jquery-selectors