event.x,event.clientX,event.offsetX區(qū)別
更新時間:2006年11月09日 00:00:00 作者:
event.x,event.clientX,event.offsetX區(qū)別,需要的朋友可以參考下。
x:設(shè)置或者是得到鼠標相對于目標事件的父元素的外邊界在x坐標上的位置。
clientX:相對于客戶區(qū)域的x坐標位置,不包括滾動條,就是正文區(qū)域。
offsetx:設(shè)置或者是得到鼠標相對于目標事件的父元素的內(nèi)邊界在x坐標上的位置。
screenX:相對于用戶屏幕。
測試代碼一:
[code]
<html>
<head>
</head>
<script>
function reload(){
window.location.reload("http://chabaoo.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);//如果是鼠標點擊“刷新”按鈕,則跟鼠標點擊時的位置有關(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="確定要退出本頁嗎?";
}else
{
alert("你在刷新");
}
}
</script>
[/html]
演示代碼二:
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
clientX:相對于客戶區(qū)域的x坐標位置,不包括滾動條,就是正文區(qū)域。
offsetx:設(shè)置或者是得到鼠標相對于目標事件的父元素的內(nèi)邊界在x坐標上的位置。
screenX:相對于用戶屏幕。
測試代碼一:
[code]
<html>
<head>
</head>
<script>
function reload(){
window.location.reload("http://chabaoo.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);//如果是鼠標點擊“刷新”按鈕,則跟鼠標點擊時的位置有關(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="確定要退出本頁嗎?";
}else
{
alert("你在刷新");
}
}
</script>
[/html]
演示代碼二:
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
您可能感興趣的文章:
相關(guān)文章
ajaxfileupload.js實現(xiàn)上傳文件功能
這篇文章主要為大家詳細介紹了ajaxfileupload.js實現(xiàn)上傳文件功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-04-04DVA框架統(tǒng)一處理所有頁面的loading狀態(tài)
dva 有一個管理 effects 執(zhí)行的 hook,并基于此封裝了 dva-loading 插件。下面通過本文給大家分享DVA框架統(tǒng)一處理所有頁面的loading狀態(tài),感興趣的朋友一起看看吧2017-08-08如何通過JavaScript來實現(xiàn)頁面間數(shù)據(jù)傳遞
這篇文章主要給大家介紹了關(guān)于如何通過JavaScript來實現(xiàn)頁面間數(shù)據(jù)傳遞的相關(guān)資料,在前端開發(fā)中我們常常需要從一個跳到另一個頁面,并且將當前頁面的數(shù)據(jù)傳遞過去,需要的朋友可以參考下2023-11-11javascript打印html內(nèi)容功能的方法示例
這篇文章主要介紹了javascript打印html內(nèi)容的小示例,大家參考使用2013-11-11