ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 用javascript来显示HTML控件的位置即javascript文件在ASP.NET中的运用(转)

用javascript来显示HTML控件的位置即javascript文件在ASP.NET中的运用(转)

原创 Linux操作系统 作者:jcszjswkzhou 时间:2019-06-23 18:03:06 0 删除 编辑
用javascript来显示HTML控件的位置即javascript文件在ASP.NET中的运用
1. 首先在HTML的HEAD里加入:

2.写好上面目录下的javascript文件:

如:

/**********************************************************
* In order to get the position of HTML element,we provide *
* this file.It is a javascript code. *
* Written by Yuzhibin *
* Created on July 9 2004 *
* *
* *
***********************************************************/
function getX(elementID)
{
var el = elementID
return el.offsetLeft
}
function getY(elementID)
{
var el = elementID
return el.offsetTop
}
function getElementPositionX(elemID)
{
var offsetTrail = document.getElementById(elemID);
var offsetLeft = 0;
while(offsetTrail)
{
offsetLeft += offsetTrail.offsetLeft;
offsetTrail = offsetTrail.offsetParent;
}
if (navigator.userAgent.indexOf("Mac") != -1 &&
typeof(document.body.leftMargin) != "undefined") {
offsetLeft += document.body.leftMargin;
}
return offsetLeft;
}
function getElementPositionY(elemID)
{
var offsetTrail = document.getElementById(elemID);
var offsetTop = 0;
while(offsetTrail)
{
offsetTop += offsetTrail.offsetTop;
offsetTrail = offsetTrail.offsetParent;
}
if (navigator.userAgent.indexOf("Mac") != -1 &&
typeof(document.body.leftMargin) != "undefined") {
offsetTop += document.body.topMargin;
}
return offsetTop;
}
function getElementPositionXY(elemID)
{
var offsetTrail = document.getElementById(elemID);
var offsetLeft = 24;
var offsetTop =0;
while(offsetTrail)
{
offsetLeft += offsetTrail.offsetLeft;
offsetTop += offsetTrail.offsetTop;
offsetTrail = offsetTrail.offsetParent;
}
if (navigator.userAgent.indexOf("Mac") != -1 &&
typeof(document.body.leftMargin) != "undefined") {
offsetLeft += document.body.leftMargin;
offsetLeft += document.body.leftMargin;
}
document.getElementById("txt_left").innerText = offsetLeft;
document.getElementById("txt_top").innerText = offsetTop;
}

3. 在.CS下直接用下面的方式调用:

rhombusCalendar.pTop = "javascript:getX(btn_customerRequestDateFrom)";

或: btnCtrlAddress1.Attributes["onclick"] = "javascript:getElementPositionXY('"+lblCtrlAddress1.ClientID+"')";

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-121640/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2007-08-29

  • 博文量
    3488
  • 访问量
    2621524