如何区分onmouseup和onclick事件? 用区分吗?只是概念上的问题 ,onmouseup 是当鼠标松开的时候onclick 是鼠标单击的时候 ,虽然效果上有些接近 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 click=mousedown+mouseup鼠标按下弹起为一次click,如果只按下但是移开了不算一次click onmouseup,有特殊情况,不管在哪里按下,只要弹起的时候在你目标区域上,就会触发。onclick,是必须有完整的在当前区域按下,弹起。 onmousedown、onmouseup、onclick三者都是关于鼠标的响应事件,只不过看你侧重于鼠标的哪一点。如果想在鼠标按下时触发,则用onmousedown;如果是在鼠标弹起来触发,则用onmouseup;onclick事件则是包含了onmousedown和onmouseup两个动作,一般用于单击按钮、链接等时用到。这些事件需要你多练才能理解更深 没啥好解释滴,写几句代码,做几次试验就都明白了!送你三本手册!DHTML参考手册http://download.csdn.net/source/308913样式表中文手册http://download.csdn.net/source/304124JScript语言参考http://download.csdn.net/source/308916 不是,当你按下鼠标时onmousedown,如果按住不放过会儿再松开,和马上松开这两者都会触发onmouseup和onclick,但是我们如何能区分是马上松开还是过会儿才松开呢? 计算时间?var curTime=null;function down(){//onmousedown curTime=new Date();}function up(){//onmouseup var t=new Date(); alert(t.getTime()-curTime.getTime());}时间长短应该有个标准吧,这是数字,应该不是模拟计算机 3楼的解释得很好。这类是比较难判断的,就例如ondblclick和onclick要利用间隔时间来区分,最好还是避免此类事件共用,用另一种思路去解决。 UP:有鼠標彈起來的動作。CLICK:鼠標按下並彈起來的動作。 //今天刚写的一些代码,刚好是关于事件的,你可以用来测试看.//pEvent.js文件/*检测浏览器/操作系统类型-----------------------------start-------------------------------------*/var sUserAgent = navigator.userAgent;var fAppVersion = parseFloat(navigator.appVersion);//检测是否Opera浏览器var isOpera = sUserAgent.indexOf("Opera")>-1;//检测是否Safarivar isKHTML = sUserAgent.indexOf("KHTML")>-1 || sUserAgent.indexOf("Konqueror")>-1 || sUserAgent.indexOf("AppleWebKit")>-1;//检测IEvar isIE = sUserAgent.indexOf("compatible") > -1 &&sUserAgent.indexOf("MSIE") > -1 &&!isOpera;//检测Firfoxvar isFF = sUserAgent.indexOf("Firefox")>-1&&!isKHTML;//检测Mozillavar isMoz = sUserAgent.indexOf("Gecko")>-1&&!isKHTML;var isNS4 = !isIE&&!isOpera&&!isMoz&&!isKHTML &&(sUserAgent.indexOf("Mozilla")==0) &&(navigator.appName == "Netscape") &&(fAppVersion >= 4.0 && fAppVersion <5.0);//检测操作系统var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh");var isUnix = (navigator.platform == "X11" && !isWin && !isMac);/*----------------------------- end -------------------------------------*/var $ = new Object;//首先定义addEventHandler()方法,用来代替IE与其它浏览器中的事件处理函数//参数一:要分配事件处理的对象;参数二:处理的事件名称;参数三:要分配的函数$.addEventHandler=function(oTarget,sEventType,fnHandler){ if(oTarget.addEventListener){//DOM兼容浏览器 oTarget.addEventListener(sEventType,fnHandler,false); }else if(oTarget.attachEvent){//IE oTarget.attachEvent("on" + sEventType,fnHandler); }else{//其它 oTarget["on" + sEventType] = fnHandler; }};//删除的方法$.delEventHandler=function(oTarget,sEventType,fnHandler){ if(oTarget.removeEventListener){//DOM兼容浏览器 oTarget.removeEventListener(sEventType,fnHandler,false); }else if(oTarget.detachEvent){//IE oTarget.detachEvent("on" + sEventType,fnHandler); }else{//其它 oTarget["on" + sEventType] = null; }};//格式化event对象$.formatEvent = function(oEvent){ if(isIE&&isWin){ //当事件keypress发生时,为IE创建charCode属性 oEvent.charCode=(oEvent.type=="keypress")?oEvent.keyCode:0; //由于IE仅支持冒泡阶段,因此将eventPhase的值设置为2 oEvent.eventPhase=2; oEvent.isChar = (oEvent.charCode>0);//按键是否有字符与之相关 //为IE创建pageX、pageY属性 oEvent.pageX=oEvent.clientX+document.body.scrollLeft; oEvent.pageY=oEvent.clientY+document.body.scrollTop; oEvent.preventDefault=function(){this.returnvalue=false;}; if(oEvent.type=="mouseout") oEvent.relatedTarget=oEvent.toElement; else if(oEvent.type=="mouseover") oEvent.relatedTarget=oEvent.fromElement; oEvent.stopPropagation=function(){this.cancelBubble=true;}; oEvent.target=oEvent.srcElement; oEvent.time=(new Date()).getTime(); } return oEvent;};//获取event的方法$.getEvent=function(){ if(window.event) return this.formatEvent(window.event); else return $.getEvent.caller.arguments[0];};<!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=gb2312" /><meta name="Description" content="Pgsky JavaScriptLab" /><meta name="Keywords" content="Pgsky,JavaScript" /><meta name="Robots" content="All" /><title>JavaScriptLab-10 事件</title><style type="text/css"><!--body{margin-left:0px;margin-top:10px;margin-right:0px;margin-bottom:10px;}#div{margin-left:auto;margin-right:auto;width:76%;}#pbody{border:#88cee9 1px solid;padding:15px;}--></style><script type="text/javascript" src="pEvent.js"></script></head><body><div id="div"> <div id="pbody"> <script type="text/javascript"> $.addEventHandler(window,"load",function(){ var oDiv=document.getElementById("content"); $.addEventHandler(oDiv,"mouseover",handleEvent); $.addEventHandler(oDiv,"mouseout",handleEvent); $.addEventHandler(oDiv,"mousedown",handleEvent); $.addEventHandler(oDiv,"mouseup",handleEvent); $.addEventHandler(oDiv,"click",handleEvent); $.addEventHandler(oDiv,"dblclick",handleEvent); }); //var str="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //alert(str.toLowerCase()); function handleEvent(){ var oEvent=$.getEvent(); var oTextbox=document.getElementById("test"); oTextbox.value +="\n >>> " + oEvent.type; oTextbox.value +="\n target is " +oEvent.target.tagName; if(oEvent.relatedTarget){ oTextbox.value +="\n relatedTarget is "+oEvent.relatedTarget.tagName; } } </script> <div id="content"> <textarea id="test" rows="15" cols="50"></textarea> </div> </div></div></body></html> <html xmlns="http://www.w3.org/1999/xhtml" ><head> <title>Untitled Page</title> <script type="text/javascript"> function getEventType(oEvent) { if (oEvent.type=="click") { window.alert("click事件触发"); } else { window.alert("keypress事件触发"); } } </script> </head><body> <input type="text" id="txt1" onkeypress="getEventType(event)" onclick="getEventType(event)" /></body></html> 发表于:2008-01-24 16:28:472楼 得分:0 click=mousedown+mouseup 鼠标按下弹起为一次click,如果只按下但是移开了不算一次click 二楼说的很明白 一个jQuery的问题 求助 getElementsByName 在火狐下失效,IE9正常 使用js方法解决网址过滤 check框控制radio框可编辑,帮忙看下代码有什么错误 如何修改样式。img 怎么在ie中获得文本域 选中文本的startlocation 和endlocation 关于1个form表单,根据不同的下拉列表,提交到不同的页面!! 希望各位高手帮忙 谢谢啦 不操作滚动条,怎样显示页面的底部? 日历程序 想做成下拉框联动模式的 谁帮帮忙 如何实现滚动窗口问题? ajax取值问题 求此效果
鼠标按下弹起为一次click,如果只按下但是移开了不算一次click
onclick,是必须有完整的在当前区域按下,弹起。
如果想在鼠标按下时触发,则用onmousedown;
如果是在鼠标弹起来触发,则用onmouseup;
onclick事件则是包含了onmousedown和onmouseup两个动作,一般用于单击按钮、链接等时用到。
这些事件需要你多练才能理解更深
http://download.csdn.net/source/308913样式表中文手册
http://download.csdn.net/source/304124JScript语言参考
http://download.csdn.net/source/308916
function down(){//onmousedown
curTime=new Date();
}function up(){//onmouseup
var t=new Date();
alert(t.getTime()-curTime.getTime());
}时间长短应该有个标准吧,这是数字,应该不是模拟计算机
CLICK:鼠標按下並彈起來的動作。
//今天刚写的一些代码,刚好是关于事件的,你可以用来测试看.
//pEvent.js文件
/*检测浏览器/操作系统类型
-----------------------------start-------------------------------------*/
var sUserAgent = navigator.userAgent;
var fAppVersion = parseFloat(navigator.appVersion);
//检测是否Opera浏览器
var isOpera = sUserAgent.indexOf("Opera")>-1;
//检测是否Safari
var isKHTML = sUserAgent.indexOf("KHTML")>-1
|| sUserAgent.indexOf("Konqueror")>-1
|| sUserAgent.indexOf("AppleWebKit")>-1;
//检测IE
var isIE = sUserAgent.indexOf("compatible") > -1
&&sUserAgent.indexOf("MSIE") > -1
&&!isOpera;
//检测Firfox
var isFF = sUserAgent.indexOf("Firefox")>-1&&!isKHTML;
//检测Mozilla
var isMoz = sUserAgent.indexOf("Gecko")>-1&&!isKHTML;
var isNS4 = !isIE&&!isOpera&&!isMoz&&!isKHTML
&&(sUserAgent.indexOf("Mozilla")==0)
&&(navigator.appName == "Netscape")
&&(fAppVersion >= 4.0 && fAppVersion <5.0);
//检测操作系统
var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC")
|| (navigator.platform == "Macintosh");var isUnix = (navigator.platform == "X11" && !isWin && !isMac);
/*
----------------------------- end -------------------------------------*/
var $ = new Object;
//首先定义addEventHandler()方法,用来代替IE与其它浏览器中的事件处理函数
//参数一:要分配事件处理的对象;参数二:处理的事件名称;参数三:要分配的函数
$.addEventHandler=function(oTarget,sEventType,fnHandler){
if(oTarget.addEventListener){//DOM兼容浏览器
oTarget.addEventListener(sEventType,fnHandler,false);
}else if(oTarget.attachEvent){//IE
oTarget.attachEvent("on" + sEventType,fnHandler);
}else{//其它
oTarget["on" + sEventType] = fnHandler;
}
};
//删除的方法
$.delEventHandler=function(oTarget,sEventType,fnHandler){
if(oTarget.removeEventListener){//DOM兼容浏览器
oTarget.removeEventListener(sEventType,fnHandler,false);
}else if(oTarget.detachEvent){//IE
oTarget.detachEvent("on" + sEventType,fnHandler);
}else{//其它
oTarget["on" + sEventType] = null;
}
};
//格式化event对象
$.formatEvent = function(oEvent){
if(isIE&&isWin){
//当事件keypress发生时,为IE创建charCode属性
oEvent.charCode=(oEvent.type=="keypress")?oEvent.keyCode:0;
//由于IE仅支持冒泡阶段,因此将eventPhase的值设置为2
oEvent.eventPhase=2;
oEvent.isChar = (oEvent.charCode>0);//按键是否有字符与之相关
//为IE创建pageX、pageY属性
oEvent.pageX=oEvent.clientX+document.body.scrollLeft;
oEvent.pageY=oEvent.clientY+document.body.scrollTop;
oEvent.preventDefault=function(){this.returnvalue=false;};
if(oEvent.type=="mouseout")
oEvent.relatedTarget=oEvent.toElement;
else if(oEvent.type=="mouseover")
oEvent.relatedTarget=oEvent.fromElement;
oEvent.stopPropagation=function(){this.cancelBubble=true;};
oEvent.target=oEvent.srcElement;
oEvent.time=(new Date()).getTime();
}
return oEvent;
};
//获取event的方法
$.getEvent=function(){
if(window.event)
return this.formatEvent(window.event);
else
return $.getEvent.caller.arguments[0];
};
<!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=gb2312" />
<meta name="Description" content="Pgsky JavaScriptLab" />
<meta name="Keywords" content="Pgsky,JavaScript" />
<meta name="Robots" content="All" />
<title>JavaScriptLab-10 事件</title>
<style type="text/css">
<!--
body{margin-left:0px;margin-top:10px;margin-right:0px;margin-bottom:10px;}
#div{margin-left:auto;margin-right:auto;width:76%;}
#pbody{border:#88cee9 1px solid;padding:15px;}
-->
</style>
<script type="text/javascript" src="pEvent.js"></script>
</head>
<body>
<div id="div">
<div id="pbody">
<script type="text/javascript">
$.addEventHandler(window,"load",function(){
var oDiv=document.getElementById("content");
$.addEventHandler(oDiv,"mouseover",handleEvent);
$.addEventHandler(oDiv,"mouseout",handleEvent);
$.addEventHandler(oDiv,"mousedown",handleEvent);
$.addEventHandler(oDiv,"mouseup",handleEvent);
$.addEventHandler(oDiv,"click",handleEvent);
$.addEventHandler(oDiv,"dblclick",handleEvent);
});
//var str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//alert(str.toLowerCase());
function handleEvent(){
var oEvent=$.getEvent();
var oTextbox=document.getElementById("test");
oTextbox.value +="\n >>> " + oEvent.type;
oTextbox.value +="\n target is " +oEvent.target.tagName;
if(oEvent.relatedTarget){
oTextbox.value +="\n relatedTarget is "+oEvent.relatedTarget.tagName;
}
}
</script>
<div id="content">
<textarea id="test" rows="15" cols="50"></textarea>
</div>
</div>
</div>
</body>
</html>
<head>
<title>Untitled Page</title>
<script type="text/javascript">
function getEventType(oEvent)
{
if (oEvent.type=="click")
{ window.alert("click事件触发"); }
else
{ window.alert("keypress事件触发"); }
}
</script>
</head>
<body>
<input type="text" id="txt1" onkeypress="getEventType(event)" onclick="getEventType(event)" />
</body>
</html>
click=mousedown+mouseup
鼠标按下弹起为一次click,如果只按下但是移开了不算一次click
二楼说的很明白