0

我有以下代码,第一个警报给了我一个 X,但是 if 块永远不会触发。我确定这很简单,我做错了...

$('.collectionofdates1>.datenumber').click(function(){
    alert($(this).html());
    if($(this).html() == "X"){
    alert('asdf');
    return false;
    }
else{
    $('.collectionofdates1 .datenumber').removeClass('selecteddate');
$(this).addClass('selecteddate');
}
});
4

1 回答 1

0

2 条建议:

1)在你的选择器中放置空格:$('.collectionofdates1 > .datenumber')

2) 当你的意思是 text() 时使用 text(),而不是 html()。还使用 .trim() 确保您没有空格:if($(this).text().trim() == 'X'){

于 2012-09-26T18:42:59.767 回答