JQuery 鼠标点击其它地方隐藏层
2012-03-08 10:39
453 查看
<!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>test</title> <style type="text/css"> .div{ padding:10px; border:1px dotted red; position:absolute; display:none; cursor:pointer;} </style> <script src="jquery-1.2.6.min.js"></script> <script type="text/javascript"> $(function(){ $("input[id=search]").focus(function(even){ var pos=$(this).offset(); $(".div").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"){ $(".div").css("display","block") }else{ $(".div").css("display","none"); } } } }) </script> </head> <body style=" padding-left:300px;"> <input id="search" /> <div class="div"> <a href="#" target="_blank">打开我的链接</a> </div> </body> </html>
IE下,event对象有srcElement属性,但是没有target属性;Firefox下,event对象有target属性,但是没有srcElement属性.但他们的作用是相当的,即:
firefox 下的 event.target = IE 下的 event.srcElement
event.srcElement ? event.srcElement : event.target;
相关文章推荐
- JQuery 鼠标点击其它地方隐藏层
- 基于jquery鼠标点击其它地方隐藏层的实例代码
- 基于jquery鼠标点击其它地方隐藏层的实例代码
- jQuery实现点击除了特定div的页面其它地方,隐藏该div功能。
- 点击页面其它地方隐藏div所想到的jQuery的delegate
- 由点击页面其它地方隐藏div所想到的jQuery的delegate
- 由点击页面其它地方隐藏div所想到的jQuery的delegate
- jQuery实现鼠标点击div外的地方div隐藏
- 由点击页面其它地方隐藏div所想到的jQuery的delegate
- 鼠标点击页面的其它地方div自动隐藏
- jQuery实现点击其它地方隐藏该div
- 点击页面其它地方隐藏div所想到的jQuery的delegate
- 点击页面其它地方隐藏div所想到的jQuery的delegate
- 关于鼠标点击其他地方隐藏层的实例(要引入jquery包哦)
- jQuery实现鼠标点击div外的地方div隐藏消失的效果
- 由点击页面其它地方隐藏div所想到的jQuery的delegate
- jQuery实现右侧功能栏、点击其它地方,右侧功能栏隐藏
- 点击页面其它地方隐藏div所想到的jQuery的delegate
- 由点击页面其它地方隐藏div所想到的jQuery的delegate
- 由点击页面其它地方隐藏div所想到的jQuery的delegate