PDA

View Full Version : بدست آوردن top , left i یک image buttonدر حالت اجرا



hanis29268
جمعه 21 بهمن 1390, 13:10 عصر
با سلام
چه طوری میتونم top و left یک image button رو بدست بیارم؟؟
با تشکر

Naranj
شنبه 22 بهمن 1390, 03:10 صبح
از این کد استفاده کنید


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function getPosition(obj) {
var topValue = 0, leftValue = 0;
while (obj) {
leftValue += obj.offsetLeft;
topValue += obj.offsetTop;
obj = obj.offsetParent;
}

alert(leftValue);
alert(topValue);

}


</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:ImageButton ID="ImageButton1" OnClientClick ="getPosition(this)" runat="server" />

</div>
</form>
</body>
</html>