0
我有一個文本框列表,其中用戶可以放置一個字母,但是當一個錯誤的字母被丟棄在文本框內我想addClass("danger")
我想只在錯誤的字母文本框中添加類我還附上了一張截圖來說明問題。
文本框具有的box
指定名稱的類。
現在我的下拉功能如下。
function dropabc(event) {
if ($(objBox).attr("correct1") != event.target.id) {
$(".imageError").fadeIn('slow').delay(1000).hide(0);
console.log("error");
$(this).addClass('danger');
} else {
console.log(event.target.id);
console.log("ok");
}
}
$(this).addClass("danger")
但是,這是行不通的,我只是想給danger
類添加到其上一個錯誤的值被丟棄箱。
//makes all the textbox red
$(".box").addClass("danger")
任何幫助將不勝感激!
這是jQuery UI的拖動和投擲的功能,這是工作的罰款:
var objBox;
$('.drag').draggable({
revert: true,
helper: 'clone',
cursor: 'pointer',
start: function(event, ui) {
$(this).fadeTo('fast', 0.5);
objBox=$(this);
},
stop: function(event, ui) {
$(this).fadeTo(0, 1);
}
});
$("#textbox, .box").droppable({
hoverClass: "hoverPath",
drop: function(event, ui) {
var $this = $(this);
if ($this.val() == '') {
$this.val(ui.draggable.text());
$(this).addClass("checkDiv");
$(this).each(function(i, el){
$(el).addClass(myid[3]);
});
}
var empty = $(this).parent().find("input").filter(function() {
return this.value === "";
});
if(empty.length) {
console.log(empty.length);
}
else{
console.log("done");
}
}
});
這是這是呼應文本框的數量的PHP代碼:你只是運行
for($x = 0 ; $x < count($code_words); $x++){
echo "<input id='".$code_words[$x]."' ondrop='dropabc(event)' class='box' type='textbox'/>";
}
因此,舉例來說,如果我把字母「T」下面的文本框,但它不應該在那裏,文本框上我放棄它應該添加類「危險」? – Evochrome
是的,我確實想要做這個 –
你有沒有我們可以編輯的例子?像JSFiddle或Codepen一樣? – Evochrome