有一个图片,如何让它在被点击时触发某个事件,而且被拖动时不触犯这个事件呢? 拖动无非就是控制三个事件:onmousedown onmousemove onmouseup 你可以在 onmousedown 事件里加一个延时器 setTimeout,让它在比如300毫秒之后才开始拖动。而在 onmouseup 事件里加一段代码取消这个延时处理。这样就可以给你 300 毫秒的时间,若是 onclick 就不会触发拖动,若确实是拖动则在 300 毫秒之后开始运行。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在onmouseup 里判断有没有拖动过, 有就不换图片,没有就换图,表示只点击,不用onclick可能会更好 onmousemove=funciton(){//设一个标志拖动过了}onmouseout=funciton(){//检查标志是否触发过onmouseover事件(拖动过)有就不换图else 换图//清除标志} 楼主跟说书一样的忽悠, 你要是搞一个 alert() 那是不行了, 触发什么事件? ...最近看东西总是很粗心呀...<!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"><!-- DW6 --><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>shawl.qiu template</title><style type="text/css">/* <![CDATA[ *//* ]]> */</style><script type="text/javascript">//<![CDATA[ if (navigator.appName=="Microsoft Internet Explorer") { //最大化窗口 self.moveTo(-5,-5) self.resizeTo(screen.availWidth +8,screen.availHeight+8) //这个脚本定义的宽度其实比原窗口还要大那么一点. }//]]></script><script type="text/javascript">//<![CDATA[//]]></script><script type="text/javascript">//<![CDATA[ function fDragging(obj, e){ if(!e) e=window.event; obj.style.position='relative'; var x=parseInt(obj.offsetLeft); var y=parseInt(obj.offsetTop); var x_=e.clientX-x; var y_=e.clientY-y; if(document.addEventListener){ document.addEventListener('mousemove', inFmove, true); document.addEventListener('mouseup', inFup, true); } else if(document.attachEvent){ document.attachEvent('onmousemove', inFmove); document.attachEvent('onmouseup', inFup); } inFstop(e); inFabort(e) function inFmove(e){ var evt; if(!e)e=window.event; obj.style.left=e.clientX-x_+'px'; obj.style.top=e.clientY-y_+'px'; inFstop(e); } // shawl.qiu script function inFup(e){ var evt; if(!e)e=window.event; if(document.removeEventListener){ document.removeEventListener('mousemove', inFmove, true); document.removeEventListener('mouseup', inFup, true); } else if(document.detachEvent){ document.detachEvent('onmousemove', inFmove); document.detachEvent('onmouseup', inFup); } inFstop(e); } // shawl.qiu script function inFstop(e){ if(e.stopPropagation) return e.stopPropagation(); else return e.cancelBubble=true; } // shawl.qiu script function inFabort(e){ if(e.preventDefault) return e.preventDefault(); else return e.returnValue=false; } // shawl.qiu script }//]]></script></head><body><br /><br /><img src="images/01.jpg" width="400" height="381" onclick="defaultStatus='just a test'; return true;" onmousedown="fDragging(this, event)" /></body></html> 前端图表技术分析JS 怎么在html里面调用外部的表格,动态更新? firefox怎么执行图片加载的onload事件 HTML DOM和XML DOM有什么区别? javascript传参数问题,ASP接收数据 一个字符,比如 "+"号,要求点击后执行一个函数,这个函数能够判断出点击的这个字符是什么字符 请问大虾是这种JS加密方式是什么?如何解。 问一个弱弱的问题,急,在线等 如何去掉<FONT></FONT>标签? 我如何在客户的IE中启动服务器上的一个EXE程序 怎么用javascript写一个类似拖动条的东东?? 关于层用鼠标拖动问题
//设一个标志拖动过了
}
onmouseout=funciton(){
//检查标志是否触发过onmouseover事件(拖动过)
有就不换图
else
换图//清除标志
}
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
<style type="text/css">
/* <![CDATA[ */
/* ]]> */
</style>
<script type="text/javascript">
//<![CDATA[
if (navigator.appName=="Microsoft Internet Explorer") {
//最大化窗口
self.moveTo(-5,-5)
self.resizeTo(screen.availWidth +8,screen.availHeight+8)
//这个脚本定义的宽度其实比原窗口还要大那么一点.
}
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
function fDragging(obj, e){
if(!e) e=window.event;
obj.style.position='relative';
var x=parseInt(obj.offsetLeft);
var y=parseInt(obj.offsetTop);
var x_=e.clientX-x;
var y_=e.clientY-y;
if(document.addEventListener){
document.addEventListener('mousemove', inFmove, true);
document.addEventListener('mouseup', inFup, true);
} else if(document.attachEvent){
document.attachEvent('onmousemove', inFmove);
document.attachEvent('onmouseup', inFup);
}
inFstop(e);
inFabort(e)
function inFmove(e){
var evt;
if(!e)e=window.event;
obj.style.left=e.clientX-x_+'px';
obj.style.top=e.clientY-y_+'px';
inFstop(e);
} // shawl.qiu script
function inFup(e){
var evt;
if(!e)e=window.event;
if(document.removeEventListener){
document.removeEventListener('mousemove', inFmove, true);
document.removeEventListener('mouseup', inFup, true);
} else if(document.detachEvent){
document.detachEvent('onmousemove', inFmove);
document.detachEvent('onmouseup', inFup);
}
inFstop(e);
} // shawl.qiu script function inFstop(e){
if(e.stopPropagation) return e.stopPropagation();
else return e.cancelBubble=true;
} // shawl.qiu script
function inFabort(e){
if(e.preventDefault) return e.preventDefault();
else return e.returnValue=false;
} // shawl.qiu script
}
//]]>
</script>
</head>
<body><br />
<br />
<img src="images/01.jpg" width="400" height="381"
onclick="defaultStatus='just a test'; return true;"
onmousedown="fDragging(this, event)" />
</body>
</html>