search
HomeWeb Front-endJS Tutorialdocument.all and WEB standards_Basic knowledge

1. DOM

WEB standards are really popular now, but what is discussed below is a document.all[] that does not meet the standards. DOM - DOCUMENT OBJECT MODEL document object model provides methods to access document objects. For example, if there is a table in the document and you want to change its background color, you can use document.all[] to access the TABLE in javascript. But the DOM is also different. Because of the competition between browser manufacturers, each browser manufacturer has developed its own private DOM, which can only run correctly on its own browser. document.all[] can only run on IE. Microsoft's private DOM. In order to correctly understand the DOM, the DOM of IE4 is given

2. Understand document.all[]

Starting from IE4, IE’s object model only added document.all[ ], let’s take a look at the Description of document.all[]:
Array of all HTML tags in the document.Collection of all elements contained by the object.

That is to say, document.all[] is a document An array variable composed of all tags in , including all elements in the document object (see Example 1).

IE's document.all collection exposes all document elements. This array provides access to every element in the document.

document.all[] This array provides access to all elements in the document.

Example 1 (this allows you to understand which objects are in the document)


[Ctrl A to select all Note: If you need to introduce external Js, you need to refresh to execute
]
  Example 2 (Accessing a specific element)


[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]


The above example lets you understand how to access a specific element in the document. For example, if there is a DIV in the document
, you can use this Access this DIV using the ID, NAME or INDEX attribute of the DIV:
Copy the code
The code is as follows:

document.all["docid"]
document.all["docname"]
document.all.item("docid")
document.all.item("docname")
document. all[7] document.all.tags("div") returns an array of all DIVs in the document. In this example, there is only one DIV, so you can access it with document.all.tags("div")[0] .
  3、使用document.all[]

例3


[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

  4、标准DOM中的访问方法

  开头就说过document.all[]不符合WEB标准,那用什么来替代它呢?document.getElementById


Most third-party browsers are â€œstrict standards” implementations, meaning that they implement W3C and ECMA standards and ignore most of the proprietary object models of Internet Explorer and Netscape.If the demographic for your Web site includes users likely to use less common browsers, such as Linux aficionados, it might be a good idea to avoid IE-specific features and use the W3C DOM instead. by Internet Explorer 6, we see that IE implements significant portions of the W3C DOM.

  这段话的意思是大多数第三方浏览器只支持W3C的DOM,如果你的网站用户使用其他的浏览器,那么你最好避免使用IE的私有属性。而且IE6也开始支持W3C DOM。

  毕竟大多数人还不了解标准,在使用标准前,你还可以在你的网页中用document.all[]访问文档对象前面写到WEB标准,今天继续WEB标准下可以通过getElementById(), getElementsByName(), and getElementsByTagName()访问DOCUMENT中的任一个标签:

  1、getElementById()

  getElementById()可以访问DOCUMENT中的某一特定元素,顾名思义,就是通过ID来取得元素,所以只能访问设置了ID的元素。

  比如说有一个DIV的ID为docid:



  那么就可以用getElementById("docid")来获得这个元素。


[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

  2、getElementsByName()

  这个是通过NAME来获得元素,但不知大家注意没有,这个是GET ELEMENTS,复数ELEMENTS代表获得的不是一个元素,为什么呢?

  因为DOCUMENT中每一个元素的ID是唯一的,但NAME却可以重复。打个比喻就像人的身份证号是唯一的(理论上,虽然现实中有重复),但名字重复的却很多。如果一个文档中有两个以上的标签NAME相同,那么getElementsByName()就可以取得这些元素组成一个数组。

  比如有两个DIV:




  那么可以用getElementsByName("docname")获得这两个DIV,用getElementsByName("docname")[0]访问第一个DIV,用getElementsByName("docname")[1]访问第二个DIV。

  下面这段话有错,请看forfor的回复,但是很可惜,IE没有支持这个方法,大家有兴趣可以在FIREFOX或NETSCAPE中调试下面这个例子。(我在NETSCAPE7.2英文版和FIREFOX1.0中调试成功。)


[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

  看来最新版浏览器理解WEB标准还是有问题,我知道的只有盒模型、空格BUG、漂浮BUG、FLASH插入BUG,从document.getElementsByName可以看出FIREFOX,NETSCAPE理解标准有偏差,但forfor说的对:要灵活应用标准。

  3、getElementsByTagName()

  这个呢就是通过TAGNAME(标签名称)来获得元素,一个DOCUMENT中当然会有相同的标签,所以这个方法也是取得一个数组。

  下面这个例子有两个DIV,可以用getElementsByTagName("div")来访问它们,用getElementsByTagName("div")[0]访问第一个DIV,用

getElementsByTagName("div")[1]访问第二个DIV。


[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
  总结一下标准DOM,访问某一特定元素尽量用标准的getElementById(),访问标签用标准的getElementByTagName(),但IE不支持getElementsByName(),所以就要避免使用getElementsByName(),但getElementsByName()和不符合标准的document.all[]也不是全无是处,它们有自己的方便之处,用不用那就看网站的用户使用什么浏览器,由你自己决定了。

  关于document.getElementsByName

  IE当然支持 å¯ä»¥è¯´IE更忠于html/xhtml标准(嘿嘿 åŽŸæ¥firefox也不咋地 å¹¸ç¾ä¹ç¥¸ä¸€ä¸‹^_^)

  按照O'REILLY的>中的说法 name并不是核心属性 å¹¶éžæ‰€æœ‰æ ‡ç­¾éƒ½å¯ä»¥åŠ name属性(大家可以拿我下面的例子去 validator.w3.org åšéªŒè¯)

  所以你给div加name属性理论上是不会出结果的.这一点IE很好的符合了标准~!!

  (同时也看出了符合标准也有烦人的地方~_~ æ‰€ä»¥å¤§å®¶ä¸ç”¨å¤ªæŠŠæ ‡å‡†å½“回事儿 è¿‡ä¸¤å¹´éƒ½ç”¨xml了 è¿™ä¸ªä¹Ÿè¿‡æ—¶äº†!倡导灵活的webstandard应用思想 é™¤äº†ç¬¦åˆxml思想的东西 å…¶ä»–的按浏览器的理解去做就行)

附: 


[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]


  简单来说就是DIV不支持NAME属性,所以那个document.getElementsByName的例子调试不能通过.
下面用INPUT做个例子

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

From C/C   to JavaScript: How It All WorksFrom C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor