在图片上点击某点,然后获取该点相对于该图片的坐标,该怎么做 在图片上点击某点,然后获取该点相对于该图片的坐标,该怎么做 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 offsetX,offsetY 发生事件的地点在事件源元素的坐标系统中的 x 坐标和 y 坐标。 <img src="img/menu-fouce-down_03.gif" style="width:100px;height:100px;" onclick="getPos(this,event);"/> <script type="text/javascript"> function getPos(o,e){ //alert(o.offsetLeft+":"+o.offsetTop); alert(e.offsetX+":"+e.offsetY); } </script> 老大 我想说的是非IE浏览器用的似乎不是offsetX和offsetY吧我之前一直用这个函数。楼主参考function getElementX(e) { return (e && e.layerX) || window.event.offsetX;}function getElementY(e) { return (e && e.layerX) || window.event.offsetY;} 这样试试:<script type="text/javascript">var bStart=false, o=null,coords='',x=0,y=0;function $(id){return document.getElementById(id);}function trackcoords(e){ e=e||window.event; if(bStart){ if(e.pageX || e.pageY){coords=e.pageX+','+e.pageY;o.value +=o.value==''?coords:'|'+coords; return;} coords=e.clientX+','+e.clientY; o.value +=o.value==''?coords:'|'+coords }}function imgload(){ var src='',img=null; img=document.createElement("img"); img.style.display="none"; img.onmousedown=function(){ bStart=true;trackcoords() } img.onload=function(){ this.style.display="block"; this.onload=null; } img.src='XXXX.gif'; $("imgcontainer").appendChild(img)}document.onmouseup=function(){bStart=false;}window.onload=function(){ o=$('coords');imgload()}</script> <div id='imgcontainer'></div><textarea id='coords' cols=90 rows=30 onmousedown='bStart=false' style='display:'></textarea> ie9 及 火狐下的 keyCode赋值无效,有解决方法吗 让用户访问不同的服务器,是为了让用户访问到最新的信息,例如时间信息或者ip信息被缓存了会造成错误的 解决方案是什么??? 如何用JS得到火狐浏览器中file的上传图片路径 如何禁止往网页里拖拽连接? textbox 每次变化 触发事件 如何点击一行,得到该行文本框里的值,行的背景图片改变. 帮看看DIV弹出窗口的问题 难学吗? 帮我分析一下一个很好的右键菜单 如何获取使用<input type=file>选择的文件的大小? 大家常用哪些jquery的plug-in jquery 怎么通过子元素找父元素
<script type="text/javascript">
function getPos(o,e){
//alert(o.offsetLeft+":"+o.offsetTop);
alert(e.offsetX+":"+e.offsetY);
}
</script>
老大 我想说的是非IE浏览器用的似乎不是offsetX和offsetY吧我之前一直用这个函数。楼主参考function getElementX(e) {
return (e && e.layerX) || window.event.offsetX;
}function getElementY(e) {
return (e && e.layerX) || window.event.offsetY;
}
var bStart=false, o=null,coords='',x=0,y=0;
function $(id){return document.getElementById(id);}
function trackcoords(e){
e=e||window.event;
if(bStart){
if(e.pageX || e.pageY){coords=e.pageX+','+e.pageY;o.value +=o.value==''?coords:'|'+coords; return;}
coords=e.clientX+','+e.clientY; o.value +=o.value==''?coords:'|'+coords
}
}
function imgload(){
var src='',img=null;
img=document.createElement("img");
img.style.display="none";
img.onmousedown=function(){ bStart=true;trackcoords() }
img.onload=function(){
this.style.display="block";
this.onload=null;
}
img.src='XXXX.gif';
$("imgcontainer").appendChild(img)
}document.onmouseup=function(){bStart=false;}
window.onload=function(){ o=$('coords');imgload()}
</script>
<div id='imgcontainer'></div>
<textarea id='coords' cols=90 rows=30 onmousedown='bStart=false' style='display:'></textarea>