对于在JavaScript中!document.getElementById、!document.createTextNode等这样的形式该如何理解,我想很多人并不是非常的清楚,但是看了以下的代码我想我们就会有一个非常深刻的理解。

<html>
<script type="text/javascript">
alert(document);
/* 说明document为一个对象*/
alert(document.getElementById);
alert(document.createTextNode);
/*显示document对象是否定义getElementById与createTextNode,
   由于定义了,因此显示其定义的方法原型
*/
alert(document.getElementByClass);
/*由于document对象未定义getElementByClass方法,所以显示undefined*/
/*明确上面的一些知识对于我们理解下面的一段代码非常有帮助*/
function checkSearch()
{
 if(!document.getElementById||!document.createTextNode)
 {
  return;
 }
 .......
 /*即,如果document对象没有定义getElementById与createTextNode方法,则函数停止执行*/
}
</script>
<body>
</body>
</html>
其相关的执行结果如下所示(执行环境为IE6内核的浏览器):
alert(document);
alert(document.getElementById);
alert(document.createTextNode);
alert(document.getElementByClass);

相关文章:

  1. 选择下拉列表实现跳转!
  2. 给自己的页面添加复制文章内容功能!
  3. Unicode字符编码与ASCII字符编码的关系!
  4. JavaScript中文、英文字符串比较!
  5. php中global变量的使用说明!