このステートメントに別の等しくない (!=) 値を追加するにはどうすればよいですか?
if ($(this).data("increase_priority1") && $(this).val() != 1)
等しいかどうかを判断する関数の先頭で構文を逆にしてみましたが、アイテムを完全に削除できなくなりました(1に等しくないものを含む)
if ($(this).data("increase_priority1") && $(this).val() != 1 && $(".complaint select").val() != "Too_small")
この関数は、ユーザーが苦情を選択し、問題の重要度をランク付けしたときに、「increase_priority1」の値を追加および/または削除します。値 (この場合は苦情) と重要度 (つまり、increase_priority1) これら 2 つのフィールドのいずれかが変更された場合。現時点では、重要度が変化した場合にのみ変化します。
完全な機能は次のとおりです。
var $increase_priority1 = $(".increase_priority1");
$('.ranking, .complaint select').dropkick({
change: function () {
var name = $(this)
.data("name"); //get priority name
if ($(".complaint select")
.val() === "Too_small" && $(this)
.val() == 1 && !$(this)
.data("increase_priority1")) {
//rank is 1, and not yet added to priority list
$("<option>", {
text: name,
val: name
})
.appendTo($increase_priority1);
$(this)
.data("increase_priority1", true); //flag as a priority item
}
if ($(this)
.data("increase_priority1") && $(this)
.val() != 1) {
//is in priority list, but now demoted
$("option[value=" + name + "]", $increase_priority1)
.remove();
$(this)
.removeData("increase_priority1"); //no longer a priority item
}
}
});
これをコンテキストで示すフィドル: http://jsfiddle.net/chayacooper/vWLEn/132/