event.x,event.clientX,event.offsetX區(qū)別
更新時(shí)間:2006年11月09日 00:00:00 作者:
event.x,event.clientX,event.offsetX區(qū)別,需要的朋友可以參考下。
x:設(shè)置或者是得到鼠標(biāo)相對(duì)于目標(biāo)事件的父元素的外邊界在x坐標(biāo)上的位置。
clientX:相對(duì)于客戶(hù)區(qū)域的x坐標(biāo)位置,不包括滾動(dòng)條,就是正文區(qū)域。
offsetx:設(shè)置或者是得到鼠標(biāo)相對(duì)于目標(biāo)事件的父元素的內(nèi)邊界在x坐標(biāo)上的位置。
screenX:相對(duì)于用戶(hù)屏幕。
測(cè)試代碼一:
[code]
<html>
<head>
</head>
<script>
function reload(){
window.location.reload("http://www.dbjr.com.cn");
}
</script>
<body>
<table>
<TR><TD><input type="button" name="button1" value="button1" onclick="reload();"></TD><TD></TD></TR>
<TR><TD><input type="button" name="button2" value="button2" onclick="reload();"></TD><TD></TD></TR>
</table>
<input type="button" name="update" value="刷新" onclick="reload();">
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<input type="button" name="button" value="button" onclick="reload();">
</body>
</html>
<script>
function window.onbeforeunload()
{
alert('event.clientX='+event.clientX);//如果是鼠標(biāo)點(diǎn)擊“刷新”按鈕,則跟鼠標(biāo)點(diǎn)擊時(shí)的位置有關(guān)
alert('event.offsetX='+event.offsetX);
alert('document.body.clientWidth='+document.body.clientWidth);
alert('event.clientY='+event.clientY);
alert('event.offsetY='+event.offsetY);
alert('event.altKey='+event.altKey);
if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
{
window.event.returnValue="確定要退出本頁(yè)嗎?";
}else
{
alert("你在刷新");
}
}
</script>
[/html]
演示代碼二:
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁(yè)面才能執(zhí)行]
clientX:相對(duì)于客戶(hù)區(qū)域的x坐標(biāo)位置,不包括滾動(dòng)條,就是正文區(qū)域。
offsetx:設(shè)置或者是得到鼠標(biāo)相對(duì)于目標(biāo)事件的父元素的內(nèi)邊界在x坐標(biāo)上的位置。
screenX:相對(duì)于用戶(hù)屏幕。
測(cè)試代碼一:
[code]
<html>
<head>
</head>
<script>
function reload(){
window.location.reload("http://www.dbjr.com.cn");
}
</script>
<body>
<table>
<TR><TD><input type="button" name="button1" value="button1" onclick="reload();"></TD><TD></TD></TR>
<TR><TD><input type="button" name="button2" value="button2" onclick="reload();"></TD><TD></TD></TR>
</table>
<input type="button" name="update" value="刷新" onclick="reload();">
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<input type="button" name="button" value="button" onclick="reload();">
</body>
</html>
<script>
function window.onbeforeunload()
{
alert('event.clientX='+event.clientX);//如果是鼠標(biāo)點(diǎn)擊“刷新”按鈕,則跟鼠標(biāo)點(diǎn)擊時(shí)的位置有關(guān)
alert('event.offsetX='+event.offsetX);
alert('document.body.clientWidth='+document.body.clientWidth);
alert('event.clientY='+event.clientY);
alert('event.offsetY='+event.offsetY);
alert('event.altKey='+event.altKey);
if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
{
window.event.returnValue="確定要退出本頁(yè)嗎?";
}else
{
alert("你在刷新");
}
}
</script>
[/html]
演示代碼二:
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁(yè)面才能執(zhí)行]
您可能感興趣的文章:
相關(guān)文章
前端開(kāi)發(fā)必須知道的JS之閉包及應(yīng)用
本文講的是函數(shù)閉包,不涉及對(duì)象閉包(如用with實(shí)現(xiàn))。如果你覺(jué)得我說(shuō)的有偏差,歡迎拍磚,歡迎指教。2010-07-07ajaxfileupload.js實(shí)現(xiàn)上傳文件功能
這篇文章主要為大家詳細(xì)介紹了ajaxfileupload.js實(shí)現(xiàn)上傳文件功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-04-04DVA框架統(tǒng)一處理所有頁(yè)面的loading狀態(tài)
dva 有一個(gè)管理 effects 執(zhí)行的 hook,并基于此封裝了 dva-loading 插件。下面通過(guò)本文給大家分享DVA框架統(tǒng)一處理所有頁(yè)面的loading狀態(tài),感興趣的朋友一起看看吧2017-08-08如何通過(guò)JavaScript來(lái)實(shí)現(xiàn)頁(yè)面間數(shù)據(jù)傳遞
這篇文章主要給大家介紹了關(guān)于如何通過(guò)JavaScript來(lái)實(shí)現(xiàn)頁(yè)面間數(shù)據(jù)傳遞的相關(guān)資料,在前端開(kāi)發(fā)中我們常常需要從一個(gè)跳到另一個(gè)頁(yè)面,并且將當(dāng)前頁(yè)面的數(shù)據(jù)傳遞過(guò)去,需要的朋友可以參考下2023-11-11javascript打印html內(nèi)容功能的方法示例
這篇文章主要介紹了javascript打印html內(nèi)容的小示例,大家參考使用2013-11-11javascript實(shí)現(xiàn)文字跑馬燈效果
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)文字跑馬燈效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-06-06