2012-11-23 33 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我期待着能回答更多问题的那一天,而不是我问:-) –