document.documentElement与document.body

来源:互联网 发布:物理教学软件 编辑:程序博客网 时间:2024/05/09 17:28
2008-06-12 11:36

原来HTML里是document.body
XHTML里是document.documentElement
都指的是<body>节点(OR元素)


可以这样兼容:

function getBodyObj()
{
return (document.documentElement) ? document.documentElement : document.body ;
}

在DHTML文档中对documentElement的说明是:Object that receives the reference to the document element,The root node of a typical HTML document is the html object.

body

Microsoft® Internet Explorer 6 的新增内容

当你使用 !DOCTYPE 声明指定标准兼容模式的时候,此对象将不再代表文档内容所渲染的整个表面。该对象当然可从其内容中获得其大小,但你也可以像 div 对象那样精确设置其大小。

JS IndexOf()方法
2007年09月04日 星期二 下午 07:51

返回 String 对象内第一次出现子字符串的字符位置:

strObj.indexOf(subString[, startIndex])

参数
strObj

必选项。String 对象或文字。

subString

必选项。要在 String 对象中查找的子字符串。

starIndex

可选项。该整数值指出在 String 对象内开始查找的索引。如果省略,则从字符串的开始处查找。

说明
indexOf 方法返回一个整数值,指出 String 对象内子字符串的开始位置。如果没有找到子字符串,则返回 -1,所以也可以用此方法判断某字符串中是否存在某子串

如果 startindex 是负数,则 startindex 被当作零。如果它比最大的字符位置索引还大,则它被当作最大的可能索引。

从左向右执行查找。否则,该方法与 lastIndexOf 相同。

示例
下面的示例说明了 indexOf 方法的用法。

function IndexDemo(str2){
var str1 = "BABEBIBOBUBABEBIBOBU"
var s = str1.indexOf(str2);
return(s);
}