jquery - Jquery 的 FadeIn 和 FadeOut 问题

标签 jquery html css

我已经为弹出显示编写了 html 代码,当我单击按钮时我可以看到弹出窗口(淡入),但是当将 jquery 写入淡出时。单击按钮淡入后,弹出窗口没有得到显示 谁能帮帮我。 查询:

<script
  src="https://code.jquery.com/jquery-3.2.1.js"
  integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
  crossorigin="anonymous"></script>
        <script>
           $(document).ready(function(){
             $("#alert-btn").click(function(){
                 $(".container").fadeIn('slow');
             });  
               $(".container").on('click',function(){
                 if(event.target).is('#btn-cancel'){
                     $(".container").fadeOut('slow');
                 }       
               }); 


           });
        </script>

演示在这里:

https://jsfiddle.net/VijayVj7/osv98wew/

最佳答案

你不能这样做:if(event.target).is('#btn-cancel')

试试这个:

$(document).ready(function(){
             $("#alert-btn").click(function(){
                 $(".container").fadeIn('slow');
             });  

             $(".container #btn-cancel").on('click',function(){
                 $(".container").fadeOut('slow'); 
               });          

           });

https://jsfiddle.net/osv98wew/1/

关于jquery - Jquery 的 FadeIn 和 FadeOut 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43639623/

相关文章:

jquery - 在 JQUERY 中另一个方法完成后运行一个方法

Jquery 或 CSS?...用于缩放 div

jquery - 使用 fadeToggle 单击外部来关闭 div

html - 是否有与@font-face 等效的内联?

css - 如何排列这样的图像?

javascript - Bootstrap 模态 z-index

javascript - 如何在显示侧边栏时禁用背景并单击除侧边栏以外的任何地方将关闭侧边栏

html - css float with border collapse

php - 视频加载后更改页面背景

javascript - 如何找到隐藏元素的内容?