熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

通過JS得到當前焦點(鼠標)的坐標

2022-06-13   來源: JSP教程 

  <!DOCTYPE html PUBLIC "//WC//DTD XHTML Transitional//EN" "
<html xmlns="
<head>
<meta httpequiv="ContentType" content="text/html; charset=gb" />
<meta httpequiv="XUACompatible" content="IE=EmulateIE"/>
<meta name="auther" content="fq" />
<title>獲取鼠標坐標</title>

</head>

<body>
<script type="text/javascript">
function mousePosition(ev){
if(evpageX || evpageY){
return {x:evpageX y:evpageY};
}
return {
x:evclientX + documentbodyscrollLeft documentbodyclientLeft
y:evclientY + documentbodyscrollTop documentbodyclientTop
};
}

function mouseMove(ev){
ev = ev || windowevent;
var mousePos = mousePosition(ev);
documentgetElementById(xxx)value = mousePosx;
documentgetElementById(yyy)value = mousePosy;
}

documentonmousemove = mouseMove;
</script>
X:<input id="xxx" type="text" /> Y:<input id="yyy" type="text" />
</body>
</html>


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20203.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.