<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
function shows(id){
var div = document.getElementsByTagName("div");
if(document.getElementById(id+"0")){//没有if在第一次会产生正确效果 之后就永远存在了
document.getElementById(id+"0").style.visibility = "visible";
return;
}
for(var i=0;i<div.length;i++){
if(div[i].getAttribute("id")==id){
var tool = document.createElement("div");
tool.style.visibility = "visible";
tool.setAttribute("id",div[i].getAttribute("id")+"0");
tool.style.position = "absolute";
tool.style.top = parseInt(div[i].style.top)+10+"px";
tool.style.left = "0px";
tool.innerHTML = div[i].getAttribute("id");
document.body.appendChild(tool);//建了结点一定要添加啊
continue;
}
}
}
function hide(id){
var div = document.getElementById(id+"0");
div.style.visibility = "hidden";
}
</script>
</head>
<body>
<div id="i1" onmousemove="shows('i1')" onmouseout="hide('i1')" style="position:relative;top:50px;">abc</div>
<div id="i2" onmousemove="shows('i2')" onmouseout="hide('i2')" style="position:relative;top:70px;">abc</div>
</body>
</html>