Tag: if语句

jQuery if语句来检查可见性

我试图写一个脚本,将隐藏/显示div取决于其他元素的可见性。 当我点击其他元素时,该行为应该发生。 这是我迄今为止写的: $('#column-left form').hide(); $('.show-search').click(function() { $('#column-left form').stop(true, true).slideToggle(300); if( $('#column-left form').css('display') == 'none' ) { $("#offers").show(); } else { $('#offers').hide(); } }); 它隐藏了div,但隐藏表单时不会回来。 将是伟大的任何帮助:) 编辑: 好吧,我已经设法达到预期的效果,写下这个: $('#column-left form').hide(); $('.show-search').click(function() { if ($('#column-left form').is(":hidden")) { $('#column-left form').slideToggle(300); $('#offers').hide(); } else { $('#column-left form').slideToggle(300); $("#offers").show(); } }); 我不知道它是否正确写入,但它的工作原理;)谢谢大家的帮助!

if条件中的多个条件

如果我有一个if语句需要满足这些要求: if(cave > 0 && training > 0 && mobility > 0 && sleep > 0) 有什么方法可以说,他们都大于零? 只是为了更有效的干代码? 就像是: if(cave, training, mobility, sleep > 0)

“其他”错误中意外的“其他”

我得到这个错误: 错误:“其他”中意外的“其他” 从这个if, else声明: if (dsnt<0.05) { wilcox.test(distance[result=='nt'],distance[result=='t'],alternative=c("two.sided"),paired=TRUE) } else { if (dst<0.05) { wilcox.test(distance[result=='nt'],distance[result=='t'],alternative=c("two.sided"),paired=TRUE) } else { t.test(distance[result=='nt'],distance[result=='t'],alternative=c("two.sided"),paired=TRUE) } } 这有什么问题?

更简单的方法来检查variables是否不等于多个string值?

现行法规: <?php // See the AND operator; How do I simplify/shorten this line? if( $some_variable !== 'uk' && $some_variable !== 'in' ) { // Do something } ?> 和: <?php // See the OR operator; How do I simplify/shorten this line? if( $some_variable !== 'uk' || $some_variable !== 'in' ) { // Do something else […]

IF声明是否会停止评估,如果它不符合第一个条件?

如果我有一个有两个条件的If语句 – 第一个失败,第二个条件是否会被考虑,或者是否会直接转到else ? 因此,在下面的例子中,如果myList.Count == 0 , myString会与“value”进行比较,还是会直接转到else ? if(myList.Count > 0 && myString.Equals("value")) { //Do something } else { //Do something else }

在咖啡脚本中切换case语句

我有几个不同的button,调用相同的function,我想他们包装在一个开关语句,而不是使用一堆其他条件。 任何帮助将是伟大的! events: "click .red, .blue, #black, #yellow" : "openOverlay" openOverlay: (e) -> e.preventDefault() e.stopPropagation() target = $(e.currentTarget) # the view should be opened view = if target.hasClass 'red' then new App.RedView else if target.hasClass 'blue' then new App.BlueView else if target.is '#black' then new App.BlackView else null # Open the view App.router.overlays.add view: view […]

MySQL中的ELSEIF在select查询中

我试图根据用户select的数量select不同的产品价格。 这是我正在处理的查询(它有一个语法错误): select id, (SELECT IF(qty_1<='23',price,1) ELSEIF(('23'>qty_1 && qty_2<='23'),price_2,1) ELSEIF(('23'>qty_2 && qty_3<='23'),price_3,1) ELSEIF('23'>qty_3,price_4,1) END IF) as total from product;

为什么“if(i ++ &&(i == 1))”false其中我是一个int值保持1?

{ int i = 1; if (i++ && (i == 1)) printf("Yes\n"); else printf("No\n"); } 根据我的理解,在if条件中,首先expression式( i==1 )将被评估,它应该返回1 ,然后在逻辑上与1作为i的值,所以expression式应该返回1 && 1 == 1 ,但是else部分被执行。 有人可以解释为什么else部分被执行吗?

还有,如果语句存在于C#中?

我在C#中遇到以下代码。 if(condition0) statement0; else if(condition1) statement1; else if(condition2) statement2; else if(condition3) statement3; … else if(conditionN) statementN; else lastStatement; 我的一些同事告诉我,这是一个else if陈述。 不过,我确信它实际上是一个多层嵌套的if-else语句。 我知道没有分隔符{} ,一个语句被允许在一个if或else 。 所以在这种情况下,我认为它将等同于下面的代码。 if(condition0) statement0; else if(condition1) statement1; else if(condition2) statement2; else if(condition3) statement3; else … 请注意,我改变的只是空白。 这个缩进是有效的,因为当没有分隔符的时候, else都会回到最近的if语句。 任何人都可以澄清,如果第一个例子中的else if格式被编译器对待,而不是第二个例子中嵌套的if-else格式?

案例vs如果其他如果:哪个更有效率?

可能重复: 是否“如果”比“switch()case”更快? Java中if / else和switch的相对性能是什么? 我一直在编码在运行再次….当debugging程序通过一个case语句的步骤跳转到立即匹配条件的项目,但是当相同的逻辑是指定使用if / else它遍历每个if语句直到find胜利者。 case语句是否更有效率,还是我的debugging器只是优化步骤? (不要担心语法/错误,我在SO中input,不知道它是否会编译,它的原理我后,我不想做他们作为整数,因为我隐约记得一些事情case使用带ints的偏移量)我使用C#,但我对跨编程语言的一般答案感兴趣。 switch(myObject.GetType()){ case typeof(Car): //do something break; case typeof(Bike): //do something break; case typeof(Unicycle): //do something break; case default: break; } VS Type myType = myObject.GetType(); if (myType == typeof(Car)){ //do something } else if (myType == typeof(Bike)){ //do something } else if (myType == typeof(Unicycle)){ […]