2012-11-23 56 views
-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)如果這兩個字段中的任何一個發生變化目前只有在重要性水平發生變化時纔會發生變化。

完整的功能是:

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

我不明白這個問題... – 0x499602D2

+4

你可能是想刪除元素爲$(this).val()!= 1 ** **或**'$(「.indusselect」) .val()!=「Too_small」'? – Kninnug

+0

@Kninnug當這些語句中的任何一個不正確時,我需要刪除元素。這是一個OR語句而不是AND? –

回答

2

的OR操作,當操作數至少有一個爲真爲真(可能是兩個!)。你的說法應該是:

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

||是JavaScript語法爲OR。

這將運行if如果.data("increase_priority1")是真的$(this).val() != 1$(".complaint select").val() != "Too_small")是真實的。

請注意,如果&&的第一部分爲假,解釋器將停止,也就是說:它甚至不會查看第二部分。 ||也是如此,但相反,如果||的第一部分爲真,則不會看第二部分。

+0

謝謝你的真正有用的答案和你非常明確和有用的解釋:-) –

+0

非常歡迎,這就是Stackoverflow的用處。 (: – Kninnug

+0

:-D我期待着能回答更多問題的那一天,而不是我問:-) –