阻止默认事件(event.stopPropagation()):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,user-scalable=no" /><title></title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<link href="/css/css.css" rel="stylesheet" type="text/css" />
<script>
window.onload=function(){
var oA=document.getElementsByTagName("a")[0];
oA.onclick=function(event){
event.preventDefault();
console.log("阻止了默认事件");
};
}
</script>
</head>
<body>
<a>aaa</a>
</body>
</html>

阻止事件冒泡(event.stopPropagation()):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<script src="jquery-1.8.3.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(event){
$("#z_body").slideDown(1000);
event.stopPropagation();
});
$("#z_body").click(function(event){
event.stopPropagation();
});
$(document).click(function(){
$("#z_body").slideUp();
})
});
</script>
<style>
*{margin:0px;padding:0px;}
body{max-320px;margin:0 auto;width:320px;}
#z_body{width:320px;height:auto;line-height:40px;background:#ccc;color:#000000;display:none;max-width:320px;margin-top:30px;}
#z_body ul{}
#z_body ul li{width:266px;;height:39px;line-height:39px;background:#40205d;border-top:1px solid #666666;border-bottom:1px solid #666666;list-style:none;font-size:16px;color:#fff;padding-left:54px;}
#btn{height:30px;display:block;text-align:center;font-weight:600;background:pink;width:320px;line-height:30px;position:fixed;top:0px;}
</style>
</head>
<body>
<a id="btn">菜单</a>
<div id="z_body">
<ul>
<li>网站首页</li>
<li>整形中心</li>
<li>皮肤中心</li>
<li>网站首页</li>
<li>整形中心</li>
<li>皮肤中心</li>
<li>网站首页</li>
</ul>
</div>
</body>
</html>

最新文章

  1. NFS配置(centos)
  2. sublime 关闭自动更新
  3. SQL语句大全(mysql,sqlserver,oracle)
  4. 面试问到:JDBC、hibernate、ibati
  5. JavaScript constructor 属性
  6. Linux Shell编程(25)——I/O 重定向
  7. 用数据说话,外贸产品选择(中篇)-google趋势分析法
  8. TCP是什么? 最简单的三次握手说明
  9. 使用ML.NET实现德州扑克牌型分类器
  10. android 自定义Button,抛弃写shape文件
  11. [SDOI2018]原题识别
  12. 神州数码OSPF路由汇总配置
  13. 数据机构-折半查找法(二分查找法)-Python实现
  14. [svc]glusterfs的简单部署
  15. easyui中datagrid常见功能
  16. Android MediaScanner 总纲
  17. 网卡流量监控脚本 ( Python )
  18. Coredump及调试
  19. 图的遍历[DFS][BFS]
  20. 如何在eclipse查看jdk源码(src.zip)

热门文章

  1. Octopus系列之接下来的任务
  2. 【源码下载】分享一个支持自安装自卸载的Windows服务
  3. myeclipse设置编码格式的4种情况
  4. 监听TelephonyManager的通话状态来监听手机的所有的来电
  5. 如何实现ASP.NET中网站访问量的统计
  6. ros科大讯飞语音识别环境配置
  7. 在其他页面调用 Discuz 7.2 BBS 论坛会员登录信息
  8. HDU 5313 bitset优化背包
  9. Program E-- CodeForces 18C
  10. TrueType, OpenType, PCL和PostScript字体版本nterleaved 2 of 5 Barcode Font Advantage Package