如果($(this).val()==“Spine”)而不是($(this).val()==“Spine”||“Brian”),该代码工作正常。 [英] This code is working fine if ($(this).val() == "Spine") but not ($(this).val() == "Spine"||"Brian")

查看:95
本文介绍了如果($(this).val()==“Spine”)而不是($(this).val()==“Spine”||“Brian”),该代码工作正常。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

($(this).val()==Spine)但是如果($(this) .val()==Spine||Brian)然后关闭选择菜单,然后在选择optionbodyRegion==我做错了什么?


$ b $

  $(#optionbodyRegion)。change(function(){

if($这个).val()==Spine||Brain){

document.getElementById('optioncontrast')。options [0] = new Option(Select,, false,false)
document.getElementById('optioncontrast')。options [1] = new Option(With,With,false,false)
document.getElementById('optioncontrast')。 options [2] = new Option(Without,Without,false,false)
document.getElementById('optioncontrast')。options [3] = new Option(With and Without,With and没有,假,假)


$(#contrast)。slideDown(fast); // Slide Down Effect

} else {
if($(this).val()==){
$(#contrast)。slideUp(fast); //幻灯片效果

}
}
});


解决方案

使用逻辑或<$




$ p code> if($(this).val()==Spine||Brain){


$ b ($(this).val()==Spine|| $(this)$ b $ p $ to $ p
$ b pre $ ).val()==Brain){

你可以用javascript对象代替val()的jquery对象,正如FabrícioMatté所建议的那样。它会给你带来效益。

  if(this.value ==Spine|| this.value ==Brain )


This code is working fine if ($(this).val() == "Spine") but if ($(this).val() == "Spine"||"Brian") then the selection menu closes then opens again when the selection for "optionbodyRegion" == "" What am I doing wrong?

$("#optionbodyRegion").change(function(){

                if ($(this).val() == "Spine"||"Brain") {

                    document.getElementById('optioncontrast').options[0]=new Option("Select", "", false, false)
                    document.getElementById('optioncontrast').options[1]=new Option("With", "With", false, false)
                    document.getElementById('optioncontrast').options[2]=new Option("Without", "Without", false, false)
                    document.getElementById('optioncontrast').options[3]=new Option("With and Without", "With and Without", false, false)


                    $("#contrast").slideDown("fast"); //Slide Down Effect

                } else {
                    if ($(this).val() == "" ) {
                    $("#contrast").slideUp("fast");   //Slide Up Effect

                    }
                }
            });

解决方案

You have wrong syntax in using the logical or || operator

Change

 if ($(this).val() == "Spine"||"Brain") {

To

if ($(this).val() == "Spine"|| $(this).val() == "Brain") {

You can use value with javascript object instead of val() of jquery object, as Fabrício Matté suggested. It would give you performance benefit.

if (this.value == "Spine" || this.value == "Brain")

这篇关于如果($(this).val()==“Spine”)而不是($(this).val()==“Spine”||“Brian”),该代码工作正常。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆