鼠标移开DIV或点击时,如何隐藏DIV?
我在网上找到一段JS代码,实现鼠标经过按钮时弹出DIV,但是没有鼠标移出DIV或点击DIV时隐藏DIV,有谁帮我改下?我想把它改为任意文字,或按钮的下拉菜单(不是一整行<ur><li>或<div>的下拉菜单)。
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<body>
<style type="text/css">
#tip{width:300px;height:200px;background:#ff0000;display:none;position:absolute;left:10px;top:30px;}
</style>
<div id="tip"></div>
<input type="button" value="鼠标经过" onmouseover="showTip()"/>
<script type="text/javascript">
function $(id){return document.getElementById(id)}
function showTip(){
$('tip').style.display = 'block';
$('tip').style.height = 0;
for(var i = 0;i<100;i++){
(function(){
var p = i;
setTimeout(function(){ $('tip').style.height = (p/100) * 200 + 'px';},p*5)
})()
}
}
function hideTip(){
$('tip').style.display = 'none';
$('tip').style.height = 0;
}
</script>
</body>
</html>