我想在特定的一个区域内显示坐标,而不是在整个页面。下面的代码怎么让它在特定的div中显示????
scripttype="text/javascript">functionmousePosition(ev){if(ev.pageX||ev.pageY){return{...
script type="text/javascript">
function mousePosition(ev){
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
function mouseMove(ev){
ev = ev || window.event;
var mousePos = mousePosition(ev);
document.getElementById('xxx').value = mousePos.x;
document.getElementById('yyy').value = mousePos.y;
}
document.onmousemove = mouseMove;
</script>
这个我自己解决了,现在新问题。function mousePosition(ev){
if (ev.pageX || ev.pageY) {
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
function mouseMove(ev){
ev = ev || window.event;
var mousePos = mousePosition(ev);
document.getElementById("aaa").value = mousePos.x - document.getElementById("test").offsetLeft;
document.getElementById("bbb").value = mousePos.y- document.getElementById("test").offsetTop;
}
<div><input type="text" id="aaa" />
Y:
<input type="text" id="bbb" /></div>
如何在状态栏中显示!而不再这个表单中显示! 展开
function mousePosition(ev){
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
function mouseMove(ev){
ev = ev || window.event;
var mousePos = mousePosition(ev);
document.getElementById('xxx').value = mousePos.x;
document.getElementById('yyy').value = mousePos.y;
}
document.onmousemove = mouseMove;
</script>
这个我自己解决了,现在新问题。function mousePosition(ev){
if (ev.pageX || ev.pageY) {
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
function mouseMove(ev){
ev = ev || window.event;
var mousePos = mousePosition(ev);
document.getElementById("aaa").value = mousePos.x - document.getElementById("test").offsetLeft;
document.getElementById("bbb").value = mousePos.y- document.getElementById("test").offsetTop;
}
<div><input type="text" id="aaa" />
Y:
<input type="text" id="bbb" /></div>
如何在状态栏中显示!而不再这个表单中显示! 展开
1个回答
展开全部
<script type="text/javascript">
function mousePosition(ev){
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
function mouseMove(ev){
oEl = document.elementFromPoint(event.x,event.y);
if(oEl!=NULL && oEl.id="divid1")
{
ev = ev || window.event;
var mousePos = mousePosition(ev);
document.getElementById('xxx').value = mousePos.x;
document.getElementById('yyy').value = mousePos.y;
}
}
document.onmousemove = mouseMove;
</script>
function mousePosition(ev){
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
function mouseMove(ev){
oEl = document.elementFromPoint(event.x,event.y);
if(oEl!=NULL && oEl.id="divid1")
{
ev = ev || window.event;
var mousePos = mousePosition(ev);
document.getElementById('xxx').value = mousePos.x;
document.getElementById('yyy').value = mousePos.y;
}
}
document.onmousemove = mouseMove;
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询