<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");
<html> <head> <script type="text/javascript"> function $(id) { return document.getElementById(id); } var pointCount=0; function showPoint(event) { pointCount++; var point=document.createElement("div");
<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/>";
}
else
{
alert("Total points:"+pointCount);
}
}
</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>像这样显示可以吗?
<html>
<head>
<script type="text/javascript">
function $(id)
{
return document.getElementById(id);
}
var pointCount=0;
function showPoint(event)
{
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/>";
}
function showPointsCount()
{
alert("Total points:"+pointCount);
}
</script>
</head>
<body>
<img id="img1" style="z-index:10;position:absolute;left:200px;top:100px;" onclick="showPoint(event)" src="a.jpg"/><br/>
<input type="button" value="Show points count" onclick="showPointsCount()"><br/>
<span id="sp1"></span>
</body>
</html>还是要像这样?