Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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_Popup - Fatal编程技术网

Javascript jQuery弹出/隐藏框

Javascript jQuery弹出/隐藏框,javascript,jquery,popup,Javascript,Jquery,Popup,以下是我目前的情况: 到目前为止,我决定在打开.share框时将变量设置为false和true。打开后,我希望用户能够单击框以外的任何位置来关闭它 现在它第一次工作,但在那之后的任何时候,它都会因为某种原因搞砸 $(document).ready(function() { // user clicks on report this button $(".shareThis").click(function() { // confirma

以下是我目前的情况:

到目前为止,我决定在打开.share框时将变量设置为false和true。打开后,我希望用户能够单击框以外的任何位置来关闭它

现在它第一次工作,但在那之后的任何时候,它都会因为某种原因搞砸

    $(document).ready(function() {

        // user clicks on report this button
       $(".shareThis").click(function() {

        // confirmation fades in
        $(".share-box").fadeIn("fast"),

                // Prevent events from getting pass .share-box
                $(".share-box").click(function(e){
                  e.stopPropagation();
                });
       });

      $(document.body).click(function () {
                $("body").click(function(){
                    // hide the share-box if clicked anywhere aside from the box itself
                  $(".share-box").fadeOut().removeClass("active");
                });
  });
     });
添加返回值false

  // user clicks on report this button
   $(".shareThis").click(function() {

  // confirmation fades in
      $(".share-box").fadeIn(),

      // Prevent events from getting pass .share-box
      $(".share-box").click(function(e){
        e.stopPropagation();
      });

 return false;
   });
当$'.shareThis'单击时,它也会触发$document.body。单击