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