input框 下面 紧跟着div弹出层,js取top left数值
<form><input type="text" id="searchId" onkeyup="showSearch(this)" onblur="hideSearch(this)"/>
</form>
<div style="width:300px;height:500px;border:1px solid #817F82;display:none;position: absolute;" id="showInfo">
</div>
<script>
var setSearchFlag;
function showSearch(obj){
clearSearchFlag();
var w3c=(document.getElementById)? true:false;//w3c 标准
var ns6=(w3c && (navigator.appName=="Netscape"))? true: false;//Netscape浏览器 标准的W3C
var left,top;
if (!ns6){//判断IE
var nLt = 0;
var nTp = 0;
var offsetParent = obj;
while (offsetParent!=null && offsetParent!=document.body) {
nLt += offsetParent.offsetLeft;
nTp += offsetParent.offsetTop;
offsetParentoffsetParent=offsetParent.offsetParent;
}
left = nLt;
top = nTp + obj.offsetHeight;
} else {//标准w3c
left = obj.offsetLeft -5;
top = obj.offsetTop + obj.offsetHeight;
}
$('#showInfo').css('display','block');
$('#showInfo').css('top',top);
}
function hideSearch(obj){
setSearchFlag = setTimeout(function(){$('#showInfo').css('display','none');},100);
}
function clearSearchFlag(){
window.clearTimeout(setSearchFlag);
}
</script>
摘自 wwwyuanliang10000的专栏
补充:web前端 , JavaScript ,