Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于if-else不工作的jQuery第二条语句_Jquery_If Statement_Conditional Statements - Fatal编程技术网

关于if-else不工作的jQuery第二条语句

关于if-else不工作的jQuery第二条语句,jquery,if-statement,conditional-statements,Jquery,If Statement,Conditional Statements,我想知道为什么我代码中的第二个条件不起作用。第一个条件是工作正常。正如您所看到的,我的条件是,当元素的不透明度设置为1时,单击我指定的按钮后,它将变为零,反之亦然 $(函数(){ if($(“.show hide”).css(“不透明度”)=“0”){ set1(); } else if($(“.show hide”).css(“不透明度”)=“1”){ set2(); } }); 函数set1(){ $(“.share”)。在(“单击”,函数(){ $(“.show hide”)

我想知道为什么我代码中的第二个条件不起作用。第一个条件是工作正常。正如您所看到的,我的条件是,当元素的不透明度设置为1时,单击我指定的按钮后,它将变为零,反之亦然

$(函数(){
if($(“.show hide”).css(“不透明度”)=“0”){
set1();
}     
else if($(“.show hide”).css(“不透明度”)=“1”){
set2();
} 
});
函数set1(){
$(“.share”)。在(“单击”,函数(){
$(“.show hide”).css(“不透明度”,“1”)
}); 
}
函数set2(){
$(“.share”)。在(“单击”,函数(){
$(“.show hide”).css(“不透明度”,“0”)
}); 

}
如果您测试数值,则测试功能正常

$(function (){    
        if($(".show-hide").css("opacity") == 0){
            set1();                                         
        }     
        
        else if($(".show-hide").css("opacity") == 1){
            set2();                                         
        } 
              
   
});