js能做这种效果吗? 我希望如果鼠标2秒不动(或者点下左键),则出现一个层,里面显示鼠标在当前iframe里的坐标(单位px),这个效果能做吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 当然可以,onload事件中加个方法var iTimeoutId = setTimeout("show()", 2000);function show() {// 显示坐标}onmousemove事件中,clearTimeout(iTimeoutId);iTimeoutId = setTimeout("show()", 2000); 《professional javascript》 JavaScript in the Browser -》Intervals and timeouts有详细论述,还是老外牛啊 setTimeout 尽量少用,容易造成内存泄露。用setInterval吧 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><script>var iTimeoutId;function show(){ alert('ok'); iTimeoutId = setTimeout('show()', 2000);}function wait() { clearTimeout(iTimeoutId); iTimeoutId = setTimeout('show()', 2000);}</script> </head><body style="border:1px solid;width:1024px;height:900px;" onload="iTimeoutId = setTimeout('show()', 2000);" onmousemove="wait();"> 在方形区域内有效</body></html>用setInterval,也可,但是setTimeout 尽量少用,容易造成内存泄露,不清楚,不知是哪儿看见这个报道,另,鼠标在当前iframe里的坐标,这个会吧,另,我懒得在window下加事件了,只在document.body下加,这个lz会吧 setTimeout 是无限递归调用,使用setTimeout后,网页开的时间长了,你会发现卡得很郁闷,谢谢。 ie6 firefox下测试通过<html xmlns="http://www.w3.org/1999/xhtml" ><head> <title></title> <script type="text/javascript"> window.onload = function() { document.documentElement.onclick = function() { document.getElementById("layer").style.display = "none"; } } </script></head><body><div id="layer" style="padding:4px;border:1px solid #ccc;display:none"></div><iframe src="index.aspx" /></body></html><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title></title> <script type="text/javascript"> window.onload = function() { document.documentElement.onclick = function() { var oEvent = arguments[0] || window.event; var layer = parent.document.getElementById("layer"); layer.style.display = "block"; layer.innerHTML = "x:" + oEvent.clientX + ",y:" + oEvent.clientY; } } </script></head><body> <form id="form1" runat="server"> <div> </div> </form></body></html> 这代码,如果鼠标移动到iframe外面也会触发这个事件 这个可以,但是我想了下,因为页面还是其他的onclick时间,可以会和这些事件冲突,而让用户觉得不舒服,能不能做到鼠标停留x秒之后触发,或者设置个快捷键来触发? 实际上我只是在html元素上中了onclick事件来关闭显示的层.你完全可以将这段代码的事件处理函数转移到一个button上.稍微修改一下即可. 如何使用JS将URL添加到火狐的搜藏夹? showModalDialog出现缺少对象的问题 dojo中使用Firebug Lite 怎么理解 js能做这种效果吗? 在<iframe>的<div>里获得鼠标事件. 全选/取消全选的代码怎么写? 用JS写了一个小时钟(有时针,分针,秒针那种)直接COPY就可以用 再简单不过的问题,请指教 vue.js 3源码提问 紧急援助!! 谁能帮我阅读这段奇怪的JS码
// 显示坐标
}onmousemove事件中,clearTimeout(iTimeoutId);iTimeoutId = setTimeout("show()", 2000);
有详细论述,还是老外牛啊
用setInterval吧
<html>
<head>
<script>
var iTimeoutId;function show(){
alert('ok');
iTimeoutId = setTimeout('show()', 2000);
}function wait() {
clearTimeout(iTimeoutId);
iTimeoutId = setTimeout('show()', 2000);
}
</script>
</head>
<body style="border:1px solid;width:1024px;height:900px;" onload="iTimeoutId = setTimeout('show()', 2000);" onmousemove="wait();">
在方形区域内有效
</body>
</html>用setInterval,也可,但是setTimeout 尽量少用,容易造成内存泄露,不清楚,不知是哪儿看见这个报道,
另,鼠标在当前iframe里的坐标,这个会吧,
另,我懒得在window下加事件了,只在document.body下加,这个lz会吧
<head>
<title></title>
<script type="text/javascript"> window.onload = function()
{
document.documentElement.onclick = function()
{ document.getElementById("layer").style.display = "none"; }
}
</script>
</head>
<body>
<div id="layer" style="padding:4px;border:1px solid #ccc;display:none"></div>
<iframe src="index.aspx" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script type="text/javascript"> window.onload = function()
{
document.documentElement.onclick = function()
{
var oEvent = arguments[0] || window.event;
var layer = parent.document.getElementById("layer");
layer.style.display = "block";
layer.innerHTML = "x:" + oEvent.clientX + ",y:" + oEvent.clientY;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
这代码,如果鼠标移动到iframe外面也会触发这个事件
这个可以,但是我想了下,因为页面还是其他的onclick时间,可以会和这些事件冲突,而让用户觉得不舒服,能不能做到鼠标停留x秒之后触发,或者设置个快捷键来触发?