我有一个ASP.NET网站,用户可以在其中打开ImageButton Web控件中的图像。然后,他们可以单击图像按钮,客户端功能将计算两次点击之间的“实际”距离。客户端javascript函数由asp:ImageButton的OnClientClick参数引用。仅numClick ++时,该函数实际上没有回发功能;和document.getElementID(“ labelcount”)。innerText = numClick;被执行,但是在写出整个函数时仍然发生postbakc。我该如何解决这个问题? 这是JavaScript代码:
var pos1x = 0, pos1y = 0;
var pos2x = 0, pos2y = 0;
var total = 0;
var distx = 0; disty = 0;
var redistx = 0, redisty = 0, newdist = 0;
var numClick = 0;
function Image_Click() {
numClick++;
document.getElementById("labelcount").innerText = numClick;
if (numClick % 2 == 1)
{
pos1x = event.pageX;
pos1y = event.pageY;
}
else if (numClick % 2 == 0)
{
pos2x = event.pageX;
pos2y = event.pageY;
distx = Math.abs(pos2x - pos1x);
disty = Math.abs(pos2y - pos1y);
redistx = Math.ceil(distx/50);
redisty = Math.ceil(disty / 50);
newdist = Math.ceil(Math.sqrt(redistx * redistx + redisty * redisty));
document.getElementById("lengthlabel").innerText = newdist;
total += newdist;
document.getElementById("labeltotal").innerText = total;
}
return false;
}
这里是ImageButton的.aspx
<asp:ImageButton ID="pic" runat="server" ImageAlign="Left" ImageUrl="~/MemberPages/447298.jpg" OnClientClick="return Image_Click();" />