效果图:下面的代码运行后,需要再刷新一下。 test .div_d{ padding:10px; border:1px dotted red; position:absolute; display:none; cursor:pointer;} $(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"); } } } })