2

我有这个代码。如何在每个结果上设置不同的 CSS 样式 - 正确和不正确。

CSS 样式是 wordglow1 和 wordglow2...

$(".drop").droppable({
drop: function(event, ui) {
    word = $(this).data('word');

    guesses[word].push($(ui.draggable).attr('data-letter'));

    console.log(guesses);

    if (guesses[word].length == 3) {
        if (guesses[word].join('') == word) {
            alert('Correct');
        } else {
            alert(guesses[word].join('') + ' is the incorrect spelling. The word is spelt - ' + word)
        }

        $('td[data-word=' + word + ']').droppable('disable');
        }
    }
});

这些是我需要分配给条件的类...

<div id="rightanswer" class="wordglow2"></div>
<div id="wronganswer" class="wordglow"></div> 
4

3 回答 3

0

.addClass 是你的朋友

$(".drop").droppable({
    drop: function(event, ui) {
    word = $(this).data('word');

    guesses[word].push($(ui.draggable).attr('data-letter'));

    console.log(guesses);

    if (guesses[word].length == 3) {
        if (guesses[word].join('') == word) {
            $(selector).addClass('corrent');
            alert('Correct');
        } else {
            alert('Incorrect');
            $(selector).addClass('wrong spelling')
       }

            $('td[data-word=' + word + ']').droppable('disable');
            }    
        }
    });
于 2012-07-17T15:39:42.687 回答
0

您可以使用 jQuery 将 CSS 类(文档)添加到相关元素,并根据需要设置这些类的样式。

于 2012-07-17T15:34:48.933 回答
0
$(".drop").droppable({
drop: function(event, ui) {
    word = $(this).data('word');

    guesses[word].push($(ui.draggable).attr('data-letter'));

    console.log(guesses);

    if (guesses[word].length == 3) {
        if (guesses[word].join('') == word) {
            $('td[data-word=' + word + ']').addClass("wordglow2");
            alert('Correct');
        } else {
            $('td[data-word=' + word + ']').addClass("wordglow");
            alert('Incorrect');
        }
    }
}
});
于 2012-07-18T09:08:13.520 回答