jsp里面,怎么获取鼠标在网页中的坐标?
1个回答
展开全部
封装在window.event这个类下,你可以去看看,另提供一份参考代码~
<html >
<head>
<title>JavaScript获取鼠标坐标</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
.tip {
width:200px;
border:2px solid #ddd;
padding:8px;
background:#f1f1f1;
color:#666;
}
</style>
<script type="text/javascript">
function mousePos(e){
var x,y;
var e = e||window.event;
return {
x:e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,
y:e.clientY+document.body.scrollTop+document.documentElement.scrollTop
};
};
function test(e){
document.getElementById("mjs").innerHTML = mousePos(e).x+','+mousePos(e).y;
};
</script>
</head>
<body>
<div id="mjs" class="tip"></div>
<div id="test" style="width:1000px;height:600px;background:#ccc;" onmousemove="test(event)"></div>
</body>
</html>
<html >
<head>
<title>JavaScript获取鼠标坐标</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
.tip {
width:200px;
border:2px solid #ddd;
padding:8px;
background:#f1f1f1;
color:#666;
}
</style>
<script type="text/javascript">
function mousePos(e){
var x,y;
var e = e||window.event;
return {
x:e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,
y:e.clientY+document.body.scrollTop+document.documentElement.scrollTop
};
};
function test(e){
document.getElementById("mjs").innerHTML = mousePos(e).x+','+mousePos(e).y;
};
</script>
</head>
<body>
<div id="mjs" class="tip"></div>
<div id="test" style="width:1000px;height:600px;background:#ccc;" onmousemove="test(event)"></div>
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询