51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

基于jquery鼠标点击其它地方隐藏层的实例代码

效果图:

下面的代码运行后,需要再刷新一下。
<!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><link rel="dns-prefetch" href="//www.jiangweishan.com"><link rel="dns-prefetch" href="//www.jiangweishan.comsearch.php"><link rel="dns-prefetch" href="//shang.qq.com"><link rel="dns-prefetch" href="//files.jb51.net"><link rel="dns-prefetch" href="//www.w3.org"><link rel="dns-prefetch" href="//demo.jb51.net"><link rel="dns-prefetch" href="//www.jb51.net"><link rel="dns-prefetch" href="//www.mockplus.cn"><link rel="dns-prefetch" href="//www.aliyun.com"><link rel="dns-prefetch" href="//pagead2.googlesyndication.com"><link rel="dns-prefetch" href="//weibo.com"><link rel="dns-prefetch" href="//beian.miit.gov.cn"><link rel="dns-prefetch" href="//hm.baidu.com"><link rel="dns-prefetch" href="//www.zblogcn.com"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>test</title><style type="text/css"> .div_d{ padding:10px; border:1px dotted red; position:absolute; display:none; cursor:pointer;} </style><script src="http://demo.jb51.net/jslib/jquery/jquery.js"></script><script type="text/javascript"> $(function(){ $("input[id=search]").focus(function(even){ var pos=$(this).offset(); $(".div_d").css({left:pos.left,top:pos.top+20+"px",display:"block"}); }); document.onclick=function(e){ var e=e?e:window.event; var tar = e.srcElement||e.target; if(tar.id!="search"){ if($(tar).attr("class")=="div_d"){ $(".div_d").css("display","block") }else{ $(".div_d").css("display","none"); } } } }) </script></head><body style=" padding-left:300px;"><input id="search"><div class="div_d"><a href="http://www.jb51.net" target="_blank">脚本之家</a>介绍信息</div></body></html>
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]


赞(0)
未经允许不得转载:工具盒子 » 基于jquery鼠标点击其它地方隐藏层的实例代码