Javascript jQuery内存游戏:if$(';.opened';).length;==数字运行功能。
因此,我试图在有Javascript jQuery内存游戏:if$(';.opened';).length;==数字运行功能。,javascript,jquery,Javascript,Jquery,因此,我试图在有td.opened==24时更改a.heart。我不确定到底出了什么问题,因为什么都没发生 HTML: 这是因为$('.opened')。长度在代码中只计算一次。更改元素类时,集合不会实时更新。当然,开放卡的数量不能自行改变 替换 if (openedCards == 24){ 借 每次都计算。使用计数变量是否更好?@CarlPapworth我刚刚看到了你的评论。我会使用计数变量。但是你所做的并没有错。是的,我想这两种方法都能奏效:)非常感谢你的帮助! var thisCard
td.opened
==24时更改a.heart
。我不确定到底出了什么问题,因为什么都没发生
HTML:
这是因为$('.opened')。长度在代码中只计算一次。更改元素类时,集合不会实时更新。当然,开放卡的数量不能自行改变
替换
if (openedCards == 24){
借
每次都计算。使用计数变量是否更好?@CarlPapworth我刚刚看到了你的评论。我会使用计数变量。但是你所做的并没有错。是的,我想这两种方法都能奏效:)非常感谢你的帮助!
var thisCard = $(this).text();
var activeCard = $('.active').text();
var openedCards = $('.opened').length;
$(document).ready(function() {
$('a.heart').css('color', '#CCCCCC');
$('a.heart').off('click');
function reset(){
$('td').removeClass('opened');
$('a').removeClass('visible');
$('td').removeClass('active');
};
$('td').click(openCard);
function openCard(){
$(this).addClass('opened');
$(this).find('a').addClass('visible');
if ($(".active")[0]){
if ($(this).text() != $('.active').text()) {
setTimeout(function(){
reset();
}, 1000);
}
else {
$('.active').removeClass('active');
}
}
else {
$(this).addClass("active");
}
if (openedCards == 24){
$(".active").removeClass("active");
$("a.heart").css('color', '#ff63ff');
$("a.heart").off('click');
}
}
});
if (openedCards == 24){
if ($('.opened').length == 24){