您的位置:首页 > Web前端 > HTML

HTML页面中编写一个提示框,动态定位与提示不同语句

2012-11-24 17:38 232 查看
HTML页面中编写一个提示框,动态定位与提示不同语句,当鼠标经过,显示。移走,就消失。

1.写一个div

2.进行js编写,写一个函数,进行处理。

DIV:

<div
style="border:1px dashed #800000; padding:15px;display:none;
position:fixed;width:160px;height:300px;background-color:#fdd2c5;font-size:19px;z-index:auto"    id="divTips" name="divTips">
</div>


<script language="javascript">
function showTips(event,tips){
x=event.clientX;
y=event.clientY;
var obj;
obj=document.getElementById("divTips");
obj.innerHTML=tips;
obj.style.left=x;
obj.style.top=y;
obj.style.display="";
//  document.getElementById("divTips").style.display="block";
}

function hiddenTips(){
document.getElementById("divTips").style.display="none";
}

</script>


调用:

<div onmouseover="showTips(event,'你好')" onmouseout="hiddenTips();" style="border:1px;background-color:black;width:160px;height:20px;">显示当前的标题</div>

<div onmouseover="showTips(event,'你dddddddd好')" onmouseout="hiddenTips();" style="border:1px;background-color:red;width:160px;height:20px;">显示当前的标题</div>
<div onmouseover="showTips(event,'你好11111')" onmouseout="hiddenTips();" style="border:1px;background-color:orange;width:160px;height:20px;">显示当前的标题</div>


整个HTML文件:

<!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>无标题文档</title>

<script language="javascript"> function showTips(event,tips){ x=event.clientX; y=event.clientY; var obj; obj=document.getElementById("divTips"); obj.innerHTML=tips; obj.style.left=x; obj.style.top=y; obj.style.display=""; // document.getElementById("divTips").style.display="block"; } function hiddenTips(){ document.getElementById("divTips").style.display="none"; } </script>

</head>

<body>

<div onmouseover="showTips(event,'你好')" onmouseout="hiddenTips();" style="border:1px;background-color:black;width:160px;height:20px;">显示当前的标题</div> <div onmouseover="showTips(event,'你dddddddd好')" onmouseout="hiddenTips();" style="border:1px;background-color:red;width:160px;height:20px;">显示当前的标题</div> <div onmouseover="showTips(event,'你好11111')" onmouseout="hiddenTips();" style="border:1px;background-color:orange;width:160px;height:20px;">显示当前的标题</div>
<div onmouseover="showTips('你好22222')" onmouseout="hiddenTips();" style="border:1px;background-color:black;width:160px;height:20px;">显示当前的标题</div>
<div onmouseover="showTips('你好33333')" onmouseout="hiddenTips();" style="border:1px;background-color:black;width:160px;height:20px;">显示当前的标题</div>
<div onmouseover="showTips('你好44444')" onmouseout="hiddenTips();" style="border:1px;background-color:black;width:160px;height:20px;">显示当前的标题</div>

<div style="left:100px; top:3000;">test</div>
<div
style="border:1px dashed #800000; padding:15px;display:none;
position:fixed;width:160px;height:300px;background-color:#fdd2c5;font-size:19px;z-index:auto" id="divTips" name="divTips">
</div>

</body>
</html>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: