document.layers、document.all、document.getElementById区别

1. document.layers是Netscape 4.x的专有属性

是Netscape 4.x专有的属性,是一个代表所有由储如<div><layer>等定位了的元素的数组。通常也是用<div>或<layer>对象的id属性来引用的,但是这里面不包含除此以外的其它元素。 

2. document.all

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


其实这两个属性没什么可比性,大概你经常看到他们同时出时,这有一个历史原因。在第四代浏览器出现的时候,标准相当混乱,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能够早日作古,让标准早日深入人心! 

3. document.getElementById

最初被定义为 HTMLDocument (HTML DOM)接口的一个成员,但是在后来的 2 级 DOM 中移入到 Document (XML DOM)接口中。
document.getElementById属于host object,它是一个function,但是它并没有被定义在ECMAScript中而是DOM接口的一部分。

各浏览器对document.getElementById等方法的实现差异



最新版的chrome和opera浏览器也支持document.all  

document.layer和document.all都是过时的写法,现在一般用document.getElementById

火狐官方文档 https://developer.mozilla.org/en-US/docs/Mozilla_Web_Developer_FAQ#JavaScript_doesn.E2.80.99t_work.21_Why.3F

Some proprietary document objects such as document.all and document.layers are not part of the W3C DOM and are not supported in Mozilla. (There is partial undetectable support for document.all, though, in newer versions of Mozilla. However, that functionality only exists for compatibility with sites authored specifically for IE. You should not rely on Mozilla’s document.all support on new pages.) The method document.getElementById() can be used instead.

In the Standards mode Mozilla does not generate implicit top-level JavaScript variable bindings for elements with the id or name attribute. The correct way to access an element by id is to call the document.getElementById() method with the id as a string as the argument.

Also, old client sniffers can shut out new browsers. The point of having a common API (the W3C DOM) is interoperability, and checking for a particular browser defeats that purpose. When working with the DOM, it is better to check for the existence of the methods and objects you are planning on using. For example, the existence of document.getElementById() can be checked as follows:

if(document.getElementById) {
   /* code that uses document.getElementById() */
}



通常用下面的if-else判断浏览器类型

 if (document.layers) {
           
 } else if (document.all) {

 } else if (document.getElementById) {
           
 }


For Opera :

if (navigator.userAgent.indexOf("Opera")!=-1
    && document.getElementById) type="OP";
Internet Explorer e.g. IE4 upwards :

if (document.all) type="IE";
For Netscape version 4 :

if (document.layers) type="NN";
Mozila e.g. Netscape 6 upwards

if (!document.all && document.getElementById) type="MO";



参考: http://www.jb51.net/article/29091.htm

http://www.jb51.net/article/28283.htm

http://www.webconcerns.co.uk/javascript/dhtml/dhtml_page.asp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
我写了一个js代码module.exports.points=[ [99.8653,22.3603], [114.9822,22.7371], [102.5558,22.8008], [103.344,23.2606], [102.5608,23.2823], [106.7131,23.292], [103.3142,23.2938], [101.9842,23.3834], [106.7964,23.3984], [102.2291,23.4502], [114.5827,23.7578]],在html中写了缓冲功能 //创建缓冲区 const graphicsLayer = new GraphicsLayer(); map.add(graphicsLayer); const resultsLayer = new GraphicsLayer(); map.addMany([graphicsLayer, resultsLayer]); const points=require('./point.js').points; //创建points数组 const pointArray = []; for (let i = 0; i < points.length; i++){ pointArray.push([points[i][0], points[i][1]]); } const multipoint = new Multipoint({ ponits:pointArray }) ; const simpleMarkerSymbol={ type: "simple-marker", color: [226, 119, 40], outline:{ color: [255, 255, 255], width: 1 } } ; const multipointGraphics = multipoint.points.map((point)=>{ return new Graphic({ geometry:{ type: "point", longitude: point[0], latitude: point[1] } , symbol: simpleMarkerSymbol }) ; } ); graphicsLayer.addMany(multipointGraphics); view.ui.add(document.getElementById("controls"), "top-right"); document.getElementById("earthquake").addEventListener("click", visual); document.getElementById("buffer").addEventListener("click", createBuffers); document.getElementById("reset").addEventListener("click", resetGraphics); document.getElementById("intersect").addEventListener("click", findIntersect); document.getElementById("union").addEventListener("click", createUnion); document.getElementById("heatmap").addEventListener("click", creatheatmap); document.getElementById("colse").addEventListener("click", closeheatmap); let bufferGraphics = []; function createBuffers(){ if (bufferGraphics.length > 0){ return; } bufferGraphics = multipointGraphics.map((pointGraphic) =>{ const buffer = geometryEngine.geodesicBuffer( pointGraphic.geometry, 10, "kilometers" ) ; return new Graphic({ geometry: buffer, symbol:{ type: "simple-fill", color: [227, 139, 79, 0.5], outline:{ color: [255, 255, 255, 255], }, }, }); } ); resultsLayer.addMany(bufferGraphics);存在一些问题可以帮我解决吗
最新发布
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值