我正在尝试设计经典代码破解游戏的客户端,并且正在尝试为尝试设置ID和类,但是我不确定是否正确完成了语法,并且语法是否正确,因为什么也没有直到所有问题解决为止。注释是说明,并且有嵌套循环。 对于(var i = NUM_ATTEMPTS; i> 0; i-){
//for each attempt, we create a div
var newDiv = document.createElement("div");
// set its id and class
$('div').addClass('attempt');
$('div').attr("id", "attempt"+[i])
// create a span, and set its id and class
var newSpan = document.createElement("span");
$('span').addClass('futureattempt');
$('span').attr("id", "attempt"+[i]+"pegs")
//...
//...
// then add 5 images including ids and classes. The img source could be empty or could be the hole.png
for (var j = 1; j <= CODE_LENGTH; j++){
var newImg = document.createElement("img");
$('img').addClass('imageAttempt');
$('img').attr("src", "./images/hole.png");
$('img').attr("id", "attempt"+[i]+"_"+[j]);
$(newSpan).append(newImg);
}
//append the span to the div
$(newDiv).append(newSpan);
// create a new span for displaying result of the end-user attempt, set id and append it to the div
//...
//...
//...
// append each div to the game board
$("#gameboard").append(newDiv);
}
我最大的问题是关于我设置创建的div,span和img的ID和类的方式,因为这些是我自己完成的部分。谢谢您的帮助。