<script language="javascript">
var tip,msg,px,py;
function showTip()
{
tip=document.createElement("DIV");
tip.setAttribute("id","myTip");
tip.style.cssText="position:absolute;width:200px;height:50px;left:"+px+"px;top:"+py+"px;border:1px solid #FC3;background:#FFC;padding:3px;z-index:100";
msg="图片名称:1.gif <br> 图片大小:200*200";//这里是你需要的显示的信息
tip.innerHTML=msg;
document.body.appendChild(tip);
}
function hideTip()
{
px=event.x;
py=event.y;
tip=document.getElementById("myTip");
if(tip) document.body.removeChild(tip);
}
</script>
<img src="1.gif" width="200" height="200" onmouseover="setTimeout('showTip()',2000)" onmousemove="hideTip()"/>
var tip,msg,px,py;
function showTip()
{
tip=document.createElement("DIV");
tip.setAttribute("id","myTip");
tip.style.cssText="position:absolute;width:200px;height:50px;left:"+px+"px;top:"+py+"px;border:1px solid #FC3;background:#FFC;padding:3px;z-index:100";
msg="图片名称:1.gif <br> 图片大小:200*200";//这里是你需要的显示的信息
tip.innerHTML=msg;
document.body.appendChild(tip);
}
function hideTip()
{
px=event.x;
py=event.y;
tip=document.getElementById("myTip");
if(tip) document.body.removeChild(tip);
}
</script>
<img src="1.gif" width="200" height="200" onmouseover="setTimeout('showTip()',2000)" onmousemove="hideTip()"/>
onmouseout="hideTip()"
function onMouseOver()
{
timeoutHandle = setTimeout("showTip()", 2000);
}
function onMouseOut()
{
hideTip();
}
function onMouseMove()
{
clearTimeout(timeoutHandle);
timeoutHandle = setTimeout("showTip()", 2000);
}
function onMouseOver()
{
//timeoutHandle = setTimeout("showTip()", 2000); 如果用这一句会每隔2秒闪烁一下
showTip();
}
function onMouseOut()
{
hideTip();
}
function onMouseMove()
{
hideTip(); 加这一句是div消失
clearTimeout(timeoutHandle);
timeoutHandle = setTimeout("showTip()", 2000);
}
另外还有一个问题,就是现在鼠标移出图片后,仍然会生成一个消息框,不知道为什么,怎么解决?
前面的代码只是大概示意了一下思路,没有仔细去弄,下面的绝对没问题了var timeoutHandle;
function onMouseOver()
{
clearTimeout(timeoutHandle);
timeoutHandle = setTimeout("showTip()", 2000);
}
function onMouseOut()
{
clearTimeout(timeoutHandle);
hideTip();
}
function onMouseMove()
{
clearTimeout(timeoutHandle);
timeoutHandle = setTimeout("showTip()", 2000);
hideTip();
}
<script language="javascript">
var tip,msg,px,py;
function showTip()
{
tip=document.createElement("DIV");
tip.setAttribute("id","myTip");
tip.style.cssText="position:absolute;width:200px;height:50px;left:"+px+"px;top:"+py+"px;border:1px solid #FC3;background:#FFC;padding:3px;z-index:100";
msg="图片名称:1.gif <br/> 图片大小:200*200";//这里是你需要的显示的信息
tip.innerHTML=msg;
document.body.appendChild(tip);
}
function hideTip()
{
tip=document.getElementById("myTip");
if(tip)document.body.removeChild(tip);
}
var timeoutHandle;
function onMouseOver()
{ document.getElementById("status").value+="over%"
px=event.x;
py=event.y;
hideTip();
clearTimeout(timeoutHandle);
timeoutHandle = setTimeout("showTip()", 2000);
}
function onMouseOut()
{
document.getElementById("status").value+="out%"
clearTimeout(timeoutHandle);
hideTip();
}
function onMouseMove()
{
px=event.x;
py=event.y;
document.getElementById("status").value+="move%"
hideTip();
clearTimeout(timeoutHandle);
timeoutHandle = setTimeout("showTip()", 2000);
}
</script>
<img src="1.gif" width="200" height="200" onmousemove="onMouseMove()"/>
<input type="text" id="status" size="150"></input>
在.cs中响应点击按钮事件
private void btCall_Click(object sender, System.EventArgs e)
{
//查询数据库代码
str="查询结果"; //str 为全局变量
}
为在javascript中调用点击按钮事件,在showTip()中加入语句document.Form1.btCall.click();即
function showTip()
{
document.Form1.btCall.click();
tip=document.createElement("DIV");
tip.setAttribute("id","myTip");
tip.style.cssText="position:absolute;width:200px;height:50px;left:"+px+"px;top:"+py+"px;border:1px solid #FC3;background:#FFC;padding:3px;z-index:1000";
tip.innerHTML=document.all.feedback.value;//传递数据库查询结果字符串str
document.body.appendChild(tip);
}其中用了一个input来传递数据库查询结果:
<input type=hidden name="feedback" value="<%=str%>">现在的效果是在showTip中加入document.Form1.btCall.click()语句后,鼠标在图片上停留2秒后,div会闪烁一下,随即消失,然后每个2秒闪烁一次,这是不是页面刷新造成的,试了好些办法都没有解决。
这个不行