检查此代码:
var test = new Array();
//I need each() to get the data from every row
$(".quiz_list_row").each(function(index){
// Gets the data necessary from HTML5 tag data
$quiz_list_id = $(this).data("quizlistId");
$quiz_level_reached = $(this).data("quizlevelReached");
test [0] = new Array($quiz_list_id,$quiz_level_reached);
$(this).click(function(){
alert("test: "+test.toString());
});
)};
div是这样的(这是正确的):
<div class="quiz_list_row" data-quizlist-id="1" data-quizlevel-reached="5">
<div class="inline" id="quiz_list_cell_id1">Quiz 1</div>
<div class="inline" id="quiz_list_cell_id2">Current level: 5</div>
</div>
<div class="quiz_list_row" data-quizlist-id="2" data-quizlevel-reached="7">
<div class="inline" id="quiz_list_cell_id1">Quiz 2</div>
<div class="inline" id="quiz_list_cell_id2">Current level: 7</div>
</div>
因此,当我单击第一个 div 时,应该在第一个警报上显示“1,5”,在第二个警报上显示“2,7”,我得到相反的结果。