JQ事件绑定效果|||事件气泡
来源:互联网 发布:vr眼镜软件 编辑:程序博客网 时间:2024/04/29 12:31
<style type="text/css">
.a{
width:100px;
border:1px solid #333;}
.c{
width:100px;
border:1px solid #333;
display:none;}
</style>
<body>
<div class="a">
<h3>习近平</h3>
<div class="c">国家主席习近平当地时间28日下午抵达布拉格,开始对捷克进行国事访问。当习近平乘坐的专机进入捷克领空时,捷克空军两架战机升空护航。这是中捷两国建交67年来中国国家主席首次对捷克进行国事访问</div>
</div>
</body>
1.加强效果
$(function(){
$("h5").bind("click",function(){
if($(this).next().is(":visible")){
$(this).next().hide();
}else{
$(this).next().show();}
})
})
2.鼠标移动的效果
$(function(){
$(".a h3").mouseover(function(){
$(".c").show();}).mouseout(function(){
$(".c").hide();})
})
$(".a h3").mouseover(function(){
$(".c").show();}).mouseout(function(){
$(".c").hide();})
})
3.合成效果
hover方法{hover(enter,leave)}
$function(){
$(".a h3").hover(function(){
$(this).next().show;
}).function(){
$(this).next.hide();
}
})
4.toggle方法
$function(){
$(".a h3").toggle(function(){
$(this).next().show();
}).function(){
$(this).next.hide();
}
})
或
$(function(){
$(".a h3").toggle(function(){
$(this).next().toggle();
},function(){
$(this).next().toggle();
})})
二:事件冒泡
$(function(){
$("span").bind("click",function(){
var txt=$("#msg").html()+"<p>内层span元素</p>";
$("#msg").html(txt);
});
$("#content").bind("click",function(){
var txt=$("#msg").html()+"<p>外层div元素</p>";
$("#msg").html(txt);
});
$("body").bind("click",function(){
var txt=$("#msg").html()+"<p>body元素</p>";
$("#msg").html(txt);
});
})
</script>
<body>
<div id="content">
外层div元素
<span>内层元素</span>
外层div元素
</div>
<div id="msg"></div>
</body>
$("span").bind("click",function(){
var txt=$("#msg").html()+"<p>内层span元素</p>";
$("#msg").html(txt);
});
$("#content").bind("click",function(){
var txt=$("#msg").html()+"<p>外层div元素</p>";
$("#msg").html(txt);
});
$("body").bind("click",function(){
var txt=$("#msg").html()+"<p>body元素</p>";
$("#msg").html(txt);
});
})
</script>
<body>
<div id="content">
外层div元素
<span>内层元素</span>
外层div元素
</div>
<div id="msg"></div>
</body>
当单机内部<span>,会输出3条记录,这就是冒泡!
1.事件对象
$("element").bind("click",function(event){});
2.停止冒泡
$("body").bind("click",function(){
var txt=$("#msg").html()+"<p>body元素</p>";
$("#msg").html(txt);
var txt=$("#msg").html()+"<p>body元素</p>";
$("#msg").html(txt);
event.stopPropagation();//停止冒泡
});
});
3.组织默认行为
event.preventDefault();
4.事件的捕获和事件冒泡相反
事件对象属性
1 0
- JQ事件绑定效果|||事件气泡
- jq 动态绑定事件
- jq事件绑定
- jq 后绑定点击事件
- 气泡事件
- js和jq中的绑定事件
- jq绑定事件的方法区别
- jq绑定事件方法及区别
- JQ绑定事件 bind(),on(),live(),delegate()
- jq事件绑定.on()、解绑事件off()用法详解
- 2016.11.14 jq(参考手册 - 事件 效果)
- Jq 事件
- jq三种实现鼠标事件绑定的方法
- jq 为新添加的元素绑定事件
- jq中绑定事件bind(),live(),delegate(),on()的优缺点
- Jq关于动态创建元素事件的绑定
- jq代码学习8--事件绑定 fl ch4 p98
- JQ中bind绑定多个事件类型
- 一个很好的省市县三级联动js文件,使用很方便
- HDU 5256 序列变换 (LIS变形&&STL)
- java就业指导
- C++作业-2
- 【慕课笔记】1-2 多线程背景知识介绍-多线程基础概念介绍
- JQ事件绑定效果|||事件气泡
- CVS SVN VSS对比整理
- 连续时间系统的时域分析
- linux下so动态库一些不为人知的秘密(上)
- C - Train Problem II——(HDU 1023 Catalan 数)
- HDU 2122 Ice_cream’s world III
- 实现开启和关闭android移动网络(做AppWidget开发的收获)
- 顺序表基本运算(线性表)c
- 对Spring对Hibernate事务管理的简单理解