首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

document.all的详细解释(document.all基本上所有浏览器可用!)

document.all是IE 4.0及以上版本的专有属性,是一个表示当前文档的所有对象的娄组,不仅包括页面上可见的实体对象,还包括一些不可见的对象,比如html注释等等。在document.all数组里面,元素不分层次,是按照其在文档中出现的先后顺序,平行地罗列的。所以可以用数字索引来引用到任何一个元素。但比较常用的是用对象id来引用一个特定的对象,比如document.all[“element”]这样。 document.layers是Netscape 4.x专有的属性,是一个代表所有由储如

<layer>等定位了的元素的数组。通常也是用
或<layer>对象的id属性来引用的,但是这里面不包含除此以外的其它元素。 其实这两个属性没什么可比性,大概你经常看到他们同时出时,这有一个历史原因。在第四代浏览器出现的时候,标准相当混乱,Netscape和微软分别推出了它们的Navigator 4.x和IE 4.0,这两个浏览器的巨大差异,也使开发者面临了一个使网页跨浏览器兼容的噩梦。而document.layer和document.all分别是两者一个最显著的标志,为了确定浏览者使用的什么浏览器,通常用是否存在document.layers和document.all来判断。 新的统一的标准用document.getElementById等系列方法来引用DOM对象,而且Netscape 6.0以后放弃了layers特征,虽然IE继续保留了document.all,但这最终没有成为DOM标准的一部分。希望document.layers和document.all能够早日作古,让标准早日深入人心!

02
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    兼容的话题:currentStyle

    3.兼容的话题:currentStyle 例 2.3.1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>     <title></title>     <style type="text/css">         #mydiv {             background-color: #28F;             width: 400px;             height: 200px;         }     </style>     <script type="text/javascript">         window.onload = function() {             ob = document.getElementById('mydiv');             alert("document.all is"+ document.all);             if (document.all) {                 alert("current is ie");                 alert(ob.currentStyle.backgroundColor);                 alert(ob.currentStyle.height);                 ob.style.background="#FF3C31";             } else {                 alert("current is Firefox");                 alert(window.getComputedStyle(ob).getPropertyValue('background-color'));                 alert(window.getComputedStyle(ob).getPropertyValue('height'));                 ob.style.background="#FF3C31";             }         }     </script> </head> <body>

    </body> </html>

    02

    javascript当中绑定事件和方法

    8.绑定事件和方法 once, long time to know that "script" must be put in behind, while "input" must be put in front, otherwise document.getElementById("button1"); can not find the "button1",alert("button1 is "+ button1); 结果就是null,为什么这次跟往常我们的印象不一样了呢?因为往常我们先写一段script,之后在body中写上诸如<INPUT TYPE="button" onclick="abc",之类的话,这样上面的abc这样的代码开始不会被执行,里面的诸如document.getElementById ("button1");也就正确了。这里为什么跟往常不一样呢?因为要在一开始时,先给button绑上事件代码,否则button无事件响应。 例 8.1(commonEventPrerequisiteIEFF.html) <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <INPUT TYPE="button" NAME="button1" ID="button1" VALUE="单击我"/> <script> function testie() { alert("单击按钮ie"); } function testFF() { alert("单击按钮FireFox"); } /**/ /*obj.addEventListener("click",function(){func("看到我了吧");},false); the third argument is: A Boolean flag value that indicates whether the event listener should use bubbling (由里向外) or capture (由外向里) event propagation. 只要我们 知道第三个参数和事件冒泡有关就可以了。缺省值为假,即冒泡的意思。具体例子参考后面的事件冒泡例子。 */ var button1 = window.document.getElementById("button1"); alert("button1 is "+ button1); alert("document.all is" + document.all); alert(typeof(window.addEventListener) + " is typeof window.addEventListener"); alert(typeof(window.attachEvent) + " is typeof window.attachEvent"); alert(window.addEventListener + " is window.addEventListener"); alert(window.attachEvent + " is window.attachEvent"); if (typeof window.attachEvent === "object") { alert("ie"); button1.attachEvent("onclick", testie); } if (typeof window.addEventListener === "function") { alert("firefox"); button1.addEventListener("click", testFF, false); } // button1.addEventListener("click",test,false); //button1.attachEvent("onclick" , test); var str = ""; </script> 更多请见:https://blog.csdn.net/qq_43650923/article/details/102210095

    00

    扫码

    添加站长 进交流群

    领取专属 10元无门槛券

    手把手带您无忧上云

    扫码加入开发者社群

    相关资讯

    热门标签

    活动推荐

      运营活动

      活动名称
      广告关闭
      领券