我有一个函数,它采用 x 和 y 值,并使用表格的行和列,找到给定的单元格。查询:
function changeNum(x,y,num)
{
var thisRow = $(".sudoku:nth-child("+y+")");
var thisCell = $(thisRow+":nth-child("+x+")");
}
声明中的某些thisCell内容导致 javascript 停止。
我有一个函数,它采用 x 和 y 值,并使用表格的行和列,找到给定的单元格。查询:
function changeNum(x,y,num)
{
var thisRow = $(".sudoku:nth-child("+y+")");
var thisCell = $(thisRow+":nth-child("+x+")");
}
声明中的某些thisCell内容导致 javascript 停止。
thisRow是一个 jQuery 集合,而不是一个字符串。用这个 :
var thisCell = $(":nth-child("+x+")", thisRow);
您也可以直接使用
var thisCell = $(".sudoku:nth-child("+y+") :nth-child("+x+")");
请注意,如果sudoku是表的类而不是行的类,那么在.sudokuand之间需要一个空格:nth-child。
尝试用 ""+ 引导
var thisCell = $(""+thisRow+":nth-child("+x+")");