- ·上一篇文章:javascript正则表达test、exec和match三者的区别
- ·下一篇文章:JS刷新当前页面的几种方法
当前位置:K88软件开发 → 文章中心 → 编程语言 → JavaScript → JS01 → 文章内容
Jquery实现点击某个区域(DIV)以外的地方关闭此DIV
实现的功能:Jquery实现点击Div,显示Div中的内容;点击Div以外的地方,关闭这个Div。
<
script type="text/javascript" src="http://www.K88.NET/js/jquery.js">
<
/script>
<
script type="text/javascript">
$(function()
{
 
 
$(document).not($("
#test2")).click(function()
{
 
 
 
 
$("
#test2").hide(200)
 
 
})
 
 
/*防止事件冒泡*/
 
 
$("
#test2").click(function(event)
{
 
 
alert('test2中的内容是:'+$("
#test2").html())
 
 
 
 
event.stopPropagation()
 
 
})
})
<
/script>
<
div style="width:300px
height:100px
background:
#ccc" id="test2">
test<
/div>
<
script type="text/javascript" src="http://www.K88.NET/js/jquery.js">
<
/script>
<
script type="text/javascript">
$(function()
{
 
 
$(document).not($("
#test2")).click(function()
{
 
 
 
 
$("
#test2").hide(200)
 
 
})
 
 
/*防止事件冒泡*/
 
 
$("
#test2").click(function(event)
{
 
 
alert('test2中的内容是:'+$("
#test2").html())
 
 
 
 
event.stopPropagation()
 
 
})
})
<
/script>
<
div style="width:300px
height:100px
background:
#ccc" id="test2">
test<
/div>
Jquery实现点击某个区域(DIV)以外的地方关闭此DIV