您的位置:首页 > Web前端 > JavaScript

XHTML和HTML中Javascript语法的一点区别

2009-07-30 11:15 351 查看
在使用下列xhtml定义
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

时,document.body.clientWidth,及大部分document.body.的属性值都会取不到,需要改为document.documentElement.clientWidth,而在老版本HTML文件中,则只能用document.body.clientWidth;

以下是我处理该问题的方法
if(jt_DialogBox.isXHTML)
{
cW = document.documentElement.clientWidth;
cH = document.documentElement.clientHeight;
sT = document.documentElement.scrollTop;
}
else
{
cW = document.body.clientWidth;
cH = document.body.clientHeight;
sT = document.body.scrollTop;
}
if (x == -1) x = Math.round((cW - this.container.offsetWidth) / 2);
if (y == -1) y = Math.round((cH - this.container.offsetHeight) / 2) +sT;
this.container.style.left = x + "px";
this.container.style.top = y + "px";
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: