<html>
<head>
<script type="text/javascript">
function $(id)
{
return document.getElementById(id);
}
var TotalCount=10;
var pointCount=0;
function showPoint()
{
if(pointCount<TotalCount)
{
pointCount++;
var point=document.createElement("div");
point.style.backgroundColor="#000000";
point.style.position="absolute";
point.style.width="4px";
point.style.height="4px";
point.style.fontSize="0";
point.style.top=event.y;
point.style.left=event.x;
point.style.zIndex=100;
document.body.appendChild(point); var pointX=parseInt(event.x)-parseInt($("img1").style.left);
var pointY=parseInt(event.y)-parseInt($("img1").style.top);
$("sp1").innerHTML+="Point "+pointCount+" : "+"("+pointX+","+pointY+")<br/>";
}
}
</script>
</head>
<body>
<img id="img1" style="z-index:10;position:absolute;left:200px;top:100px;" onclick="showPoint()" src="a.jpg"/><br/>
<span id="sp1"></span>
</body>
</html>

解决方案 »

  1.   

    Sorry,上面的版本只支持IE,这个版本支持IE和FF
    <html>
    <head>
    <script type="text/javascript">
    function $(id)
    {
    return document.getElementById(id);
    }
    var TotalCount=10;
    var pointCount=0;
    function showPoint(event)
    {
    if(pointCount<TotalCount)
    {
    pointCount++;
    var point=document.createElement("div");

    point.style.backgroundColor="#000000";
    point.style.position="absolute";
    point.style.width="4px";
    point.style.height="4px";
    point.style.fontSize="0";
    point.style.top=event.y?event.y:event.pageY;
    point.style.left=event.x?event.x:event.pageX;
    point.style.zIndex=100;
    document.body.appendChild(point);

    var pointX=parseInt(event.x?event.x:event.pageX)-parseInt($("img1").style.left);
    var pointY=parseInt(event.y?event.y:event.pageY)-parseInt($("img1").style.top);
    $("sp1").innerHTML+="Point "+pointCount+" : "+"("+pointX+","+pointY+")<br/>";
    }
    }
    </script>
    </head>
    <body>
    <img id="img1" style="z-index:10;position:absolute;left:200px;top:100px;" onclick="showPoint(event)" src="a.jpg"/><br/>
    <span id="sp1"></span>
    </body>
    </html>