码迷,mamicode.com
首页 > Web开发 > 详细

jquery论callback事件发生与并列事件发生的区别

时间:2018-01-20 22:51:59      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:blog   color   style   按钮   bsp   不用   oct   doctype   type   

不用callback:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide(1000);
    alert("现在段落被隐藏了");//事件并列,先后发生的顺序不明确
  });
});
</script>
</head>
<body>
<button>隐藏</button>
<p>这是一个段落,内容很少</p>
</body>
</html>

用callback:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide("slow",function(){
      alert("段落现在被隐藏了");//先隐藏后弹窗,有确定先后关系
    });
  });
});
</script>
</head>
<body>
<button>隐藏</button>
<p>我们段落内容,点击“隐藏”按钮我就会消失</p>
</body>
</html>

 

jquery论callback事件发生与并列事件发生的区别

标签:blog   color   style   按钮   bsp   不用   oct   doctype   type   

原文地址:https://www.cnblogs.com/lxl87/p/8321910.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!