我有这个代码。如何在每个结果上设置不同的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>
答案 0 :(得分:0)
您可以使用jQuery将CSS类(documentation)添加到相关元素,并根据需要设置这些类的样式。
答案 1 :(得分: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');
}
}
});
答案 2 :(得分: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');
}
}
}
});