[英]How to structure if…else statement to return true
Full code https://codepen.io/3noki/pen/xjyErQ 完整代码https://codepen.io/3noki/pen/xjyErQ
function checkForMatch() {
if ( $(openedCardsList[0]).is(openedCardsList[1]) ) {
$(openedCardsList[0]).removeClass('open show').addClass('match');
$(openedCardsList[1]).toggleClass('open show');
$(openedCardsList[1]).toggleClass('match');
$(openedCardsList) = [];
}
else {unFlip()}
}
This code currently only returns false values, I would like to know how to structure this in either pure DOM or pure jquery format to be able to return a true value. 该代码当前仅返回假值,我想知道如何以纯DOM或纯jquery格式构造此结构,以便能够返回真实值。
openedCardsList[0]===openedCardsList[1]
Has not returned true either 也没有返回true
When the card at array 0 and 1 are the same I want this value to be returned true. 当数组0和1处的卡相同时,我希望此值返回true。
How about checking/matching against the (FontAwesome) icon class
names? 如何检查/匹配(FontAwesome)图标
class
名称?
So when creating the card (or generating its HTML), you'd add fa
to the element's "data" (using jQuery.data()
), like this: 因此,在创建卡片(或生成其HTML)时,您可以将
fa
添加到元素的“数据”中(使用jQuery.data()
),如下所示:
function createCardHTML() {
symbol = cards.children("i");
symbol.each(function(index, item) {
$(item).addClass(cardsList[index])
// If the icon's class name is `fa-diamond`, `$(item).data('fa')` would be `diamond`.
.data('fa', cardsList[index].substring(3)); // <- here's the data
});
return symbol;
}
And then, in checkForMatch()
: 然后,在
checkForMatch()
:
var b = $('i.fa', openedCardsList[0]).data('fa');
var c = $('i.fa', openedCardsList[1]).data('fa');
var eq = ( b && c && b === c );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.