-1

このステートメントに別の等しくない (!=) 値を追加するにはどうすればよいですか?

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/

4

1 に答える 1

2

OR 演算は、オペランドの少なくとも 1 つ (場合によっては両方!) が true の場合に true です。あなたの声明は次のとおりです。

if ($(this).data("increase_priority1") && 
    ($(this).val() != 1 || $(".complaint select").val() != "Too_small")). 

||OR の Javascript 構文です。

これにより、ifif .data("increase_priority1")is trueおよび $(this).val() != 1 or $(".complaint select").val() != "Too_small") is true が実行されます。

の最初の部分&&が false の場合、インタープリターは停止することに注意してください。つまり、2 番目の部分を調べません。についても同じですが||、その逆なので、 の最初の部分||が true の場合、2 番目の部分は見られません。

于 2012-11-23T19:57:43.903 に答える