js之阻止事件冒泡(待修改)和阻止默认事件
2024-08-25 19:58:46
阻止默认事件(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>
最新文章
- NFS配置(centos)
- sublime 关闭自动更新
- SQL语句大全(mysql,sqlserver,oracle)
- 面试问到:JDBC、hibernate、ibati
- JavaScript constructor 属性
- Linux Shell编程(25)——I/O 重定向
- 用数据说话,外贸产品选择(中篇)-google趋势分析法
- TCP是什么? 最简单的三次握手说明
- 使用ML.NET实现德州扑克牌型分类器
- android 自定义Button,抛弃写shape文件
- [SDOI2018]原题识别
- 神州数码OSPF路由汇总配置
- 数据机构-折半查找法(二分查找法)-Python实现
- [svc]glusterfs的简单部署
- easyui中datagrid常见功能
- Android MediaScanner 总纲
- 网卡流量监控脚本 ( Python )
- Coredump及调试
- 图的遍历[DFS][BFS]
- 如何在eclipse查看jdk源码(src.zip)
热门文章
- Octopus系列之接下来的任务
- 【源码下载】分享一个支持自安装自卸载的Windows服务
- myeclipse设置编码格式的4种情况
- 监听TelephonyManager的通话状态来监听手机的所有的来电
- 如何实现ASP.NET中网站访问量的统计
- ros科大讯飞语音识别环境配置
- 在其他页面调用 Discuz 7.2 BBS 论坛会员登录信息
- HDU 5313 bitset优化背包
- Program E-- CodeForces 18C
- TrueType, OpenType, PCL和PostScript字体版本nterleaved 2 of 5 Barcode Font Advantage Package