offsetX Property -------------------------------------------------------------------------------- Retrieves the x-coordinate of the mouse pointer's position relative to the object firing the event. clientY Property -------------------------------------------------------------------------------- Retrieves the y-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.
是不是可以就<input type="image"...>或者<img src=".." ISMAP>进行讨论?The ISMAP attribute is used with server-side image maps. When the ISMAP attribute is included with a linked image and the user clicks the image, the image coordinates clicked are sent to the server, from which a location can be returned.
--------------------------------------------------------------------------------
Retrieves the x-coordinate of the mouse pointer's position relative to the object firing the event. clientY Property
--------------------------------------------------------------------------------
Retrieves the y-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.
<input name="tt" type="image" src="images/test.gif" value="1" onclick="ss()" />
</form>
<script>
function ss(){
alert("x="+event.offsetX+"\ny="+event.offsetY);
event.returnValue=false;
}
</script>
{
document.forms['myform'].action="tesp.aspx?x="+event.screenX+"&y="+event.screenY;
//再提交窗体,不知有无SUMBIT()方法,不想试了,若没有建一SUMBIT按钮,模拟它的点击事件 //SUMBITNAME.CLICK()
}
<input type="image">
</form>
result.htm<SCRIPT LANGUAGE="JavaScript">
<!--
var str = location.search;
var params = str.split("?")[1];
var arrPara = params.split("&");
alert("x:" + arrPara[0].split("=")[1]);
alert("y:" + arrPara[1].split("=")[1]);
//-->
</SCRIPT>
<input type="image" onclick="subForm()">
<SCRIPT LANGUAGE="JavaScript">
<!--
function subForm()
{
event.returnValue = false;
alert("x:" + event.offsetX + "\n" + "y:" + event.offsetY);
// document.forms[0].action = "result.jsp?x=" + event.offsetX + "&y=" + event.offsetY;
document.forms[0].action = "result.jsp";
document.forms[0].submit();
}
//-->
</SCRIPT>
</form>
<form name="myform" action="test.asp" onsubmit="alert(action); return false;">
<input name="tt" type="image" onclick="mz(this)"
src="http://community.csdn.net/images/CSDN_logo.gif">
</form><SCRIPT LANGUAGE="JavaScript">
function getAbsLeft(e){var l=e.offsetLeft; while(e=e.offsetParent) l += e.offsetLeft; return l;}
function getAbsTop(e) {var t=e.offsetTop; while(e=e.offsetParent) t += e.offsetTop; return t;}
//上面这两个函数是取得控件在页面里的绝对位置
function mz(e)
{
alert("你鼠标点击的坐标:\r\nx="+ window.event.clientX +" y="+ window.event.clientY);
var top = getAbsTop(e);
var left= getAbsLeft(e);
document.myform.action = "test.asp\?x="+ left +"&y="+ top;
}
</SCRIPT>
只要点击了,就产生了event,不用event取值的话,而且又不提交,仿佛不能取得值.
难道可以用其他方式取的event产生的值,关注这个答案!
function GetDefineX(ObjectID)
{
var iPositionX=ObjectID.offsetLeft;
while(ObjectID=ObjectID.offsetParent)
{
iPositionX+=ObjectID.offsetLeft;
}
return iPositionX;
}
function GetDefineY(ObjectID)
{
var iPositionY=ObjectID.offsetTop;
while(ObjectID=ObjectID.offsetParent)
{
iPositionY+=ObjectID.offsetTop;
}
return iPositionY;
}
自己提交
<style>
input.Button_Gif{height:23px; width:65; background-color: white;color: #6D869A; background-image:url(button.gif);font-size: 9pt; border:0px solide white; background-repeat: no-repeat; text-align: center; cursor:hand; padding-top:0px; vertical-align:top;}
</style>
<input type=button value="美丽按钮" class="Button_Gif" onclick="document.forms[0].submit();">
什么时间获取坐标随意啊.
即PIE
<img name="tt" src="http://community.csdn.net/images/CSDN_logo.GIF" value="1" />
<input name="ds" >
</form>
<SCRIPT LANGUAGE=vbscript>
alert(myform.tt.offsetTop)
</SCRIPT>
把input type=image换成img就可以了。
一、
<form name="myform" action="test.asp">
<input type="image" name="tt" src="http://community.csdn.net/images/CSDN_logo.GIF"/>
</form>点击后的action会变成test.asp?tt.x=5&tt.y=8提交,如果不提交则没有"?tt.x=t&tt.y=8"二、
<a href="test.asp"><img src="http://community.csdn.net/images/CSDN_logo.GIF" ismap></a>
点击后会以test.asp?5,8的形式转到下个超链接另外 这两种情况在HTML2.0 里面应该就支持了,所以大家不用担心平台的问题,我暂时就用第二种,要是有javascript取得这个值的方法不妨介绍一下啊。up者有分
event.y
不能取得坐标?IE的好象都可以~
alert(window.event);什么也没有,在 IE 下面是[object]
十分感谢各位的解答.