Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.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
Javascript jQuery-第二次单击时使用不同的函数_Javascript_Jquery - Fatal编程技术网

Javascript jQuery-第二次单击时使用不同的函数

Javascript jQuery-第二次单击时使用不同的函数,javascript,jquery,Javascript,Jquery,我正在尝试创建一个窗帘打开和关闭的效果。但由于某种原因,我的窗帘一打开就关不上了 以下是我目前掌握的信息: 我尝试了很多不同的方法,添加和删除类,切换类,这里我使用了rels $(document).ready(function () { $('.curtain').click(function(){ if ($('.curtain').attr('rel', 'open')){ $('.c

我正在尝试创建一个窗帘打开和关闭的效果。但由于某种原因,我的窗帘一打开就关不上了

以下是我目前掌握的信息:

我尝试了很多不同的方法,添加和删除类,切换类,这里我使用了rels

$(document).ready(function () {
             $('.curtain').click(function(){
                if ($('.curtain').attr('rel', 'open')){
                        $('.curtainLeft').animate({"left":"-400px"}, "slow");
                        $('.curtainRight').animate({"right":"-400px"}, "slow");
                        $('.curtain').attr('rel', 'closed');

                    } else if ($('.curtain').attr('rel', 'closed')){

                        $('.curtainLeft').animate({"left":"-0px"}, "slow");
                        $('.curtainRight').animate({"right":"-0px"}, "slow");
                        $('.curtain').attr('rel', 'open');
                    }
            });
        });
任何帮助都会很好!我迷路了!谢谢

变化

if ($('.curtain').attr('rel', 'open')){

并对第二个if语句执行相同的操作。
.attr(name,value)
将始终将属性设置为指定的值,而
.attr(name)
将仅返回值

改变

if ($('.curtain').attr('rel', 'open')){

并对第二个if语句执行相同的操作。
.attr(name,value)
将始终将属性设置为指定的值,而
.attr(name)
将仅返回值


if
中,您想检查
rel
是否
open
但在
if
中设置为
open
,您想检查
rel
是否
open
但您将其设置为
open
完美!仍然在使用jQuery!谢谢你的帮助!:)完美的仍然在使用jQuery!谢谢你的帮助!:)