return

var i = function(){

return

}

console.log(i())//undefined

return的主要作用是阻止函数继续执行,直接返回undefined

return false

<a class="baidu" href="http://www.baidu.com">百度</a>

$('.baidu').on('click',function(e){

console.log(1)

return false

})//1

并未跳转页面,当每次调用return false时,实际做了3件事情

1.event.preventDefault();

2.event.stopPropagation();

3.停止回调函数执行并立即返回

e.preventDefault

$('.baidu').on('click',function(e){

console.log(1)

e.preventDefault()

})//1

e.preventDefault()方法用来阻止浏览器继续执行默认行为,这里阻止了页面的跳转

e.stopPropagation

<div class="btn"><a class="baidu" href="http://www.baidu.com">百度</a></div>

$('.btn').on('click', function () {

console.log(520)

})

$('.btn .baidu').on('click', function (e) {

console.log(1)

e.preventDefault()

e.stopPropagation()

})

输出结果为1

e.stopPropagation阻止事件冒泡

e.stopImmediatePropagation

$('.btn .baidu').on('click',function(e){

console.log(1)

e.preventDefault()

})

$('.btn .baidu').on('click',function(e){

console.log(2)

e.preventDefault()

e.stopImmediatePropagation()

})

$('.btn .baidu').on('click',function(e){

e.preventDefault()

console.log(3)

})

$('.btn').on('click',function(e){

e.preventDefault()

console.log(4)

})

点击输出结果为1,2

e.stopImmediatePropagation()会停止一个事件继续执行,即使当前的对象上还绑定了其他处理函数,所有绑定在一个对象上的事件会按照绑定顺序执行

综上所述

return阻止函数继续执行,返回undefined

return false有三个作用,阻止浏览器默认行为,阻止事件冒泡,停止回调函数执行并立即返回

event.preventDefault阻止浏览器默认行为

event.stopPropagation阻止事件冒泡

event.stopImmediatePropagation停止一个事件继续执行,即使当前的对象上还绑定了其他处理函数,所有绑定在一个对象上的事件会按照绑定顺序执行

最新文章

  1. [CentOs7]搭建ftp服务器(3)——上传,下载,删除,重命名,新建文件夹
  2. java中equals和“==”补充
  3. wireshark长时间抓包分多个文件
  4. 【BZOJ-4568】幸运数字 树链剖分 + 线性基合并
  5. LoRaWAN协议(二)--LoRaWAN MAC数据包格式
  6. [NOIP2010] 提高组 洛谷P1541 乌龟棋
  7. [转]ELO等级分体系
  8. zhuan: ubuntu 安装 apache2
  9. 通知 Notification 详解
  10. PatrolRobot(UVa1600)BFS
  11. 基于Bresenham和DDA算法画线段
  12. Unity插件扩展中组件常用的几个方法
  13. java poi生成excel(个人例子js-jsp-java)
  14. 【AngularJS】解决ng-if中的ng-model值无效的问题(转)
  15. Tecnomatix Process Designer &amp; Process Simulate用法
  16. oracle存储过程获取异常信息码和异常信息
  17. SpringMVC中的参数绑定总结
  18. VS编译报错Error2019
  19. OpenGL ES学习笔记(二)&mdash;&mdash;平滑着色、自适应宽高及三维图像生成
  20. foreach(PHP学习)

热门文章

  1. 用axios.all处理并发请求
  2. 看年薪50W的架构师如何手写一个SpringMVC框架
  3. VC/MFC如何添加启动界面
  4. js 对象克隆方法总结(不改变原对象)
  5. ZooKeeper基础:快速部署
  6. Vmware克隆Centos6.5虚拟机网卡无法启动问题
  7. GitLab企业级代码管理仓库
  8. 如何学习numpy
  9. 算法dfs——二叉搜索树中最接近的值 II
  10. mmdetection安装教程