Javascript IE4 DOM

很多IE独有的DOM特性是沿袭自IE4的,所以有必要看看IE4 DOM的特性,与W3C的DOM模型有所区别。

[quote]IE 4 does not support childNodes[], but it provides a similar children[] array on its Document and HTMLElement objects.

IE 4 does not have a Text node type and does not consider strings of text to be children.

the textual content of a <p> tag is available through the IE 4 innerText property[/quote]

IE4 不支持childNodes[],但是有children[],功能相似;
IE4没有文本节点这回事,根本就不把文本串当做一个子节点。
要修改节点的文本内容,必须要用innerText属性。

Finding Document Elements
寻找元素

[quote]IE 4 does not support the getElementById() and getElementsByTagName() methods of the Document object.

Instead, the Document object and all document elements have an array property named all[].
Note that all[] does not simply represent the children of the document or the element; it represents all descendants, no matter how deeply nested.

If there is more than one such element (which can happen, because it is common to have multiple form elements, such as radio buttons, with the same name attribute), the result is an array of those elements. [/quote]

IE4不支持getElementById()、getElementByTagName()等Document方法。(IE6肯定支持啊)

但是,每个节点都有一个all[]属性,代表了该元素的所有子节点。该属性可以通过元素的name属性进行更进一步的访问。如果某个节点的子孙节点有多个元素含有同一个name属性,那么通过all[]返回的仍然是数组。
all[]数组本身还有一个tags()方法,通过传递一个标签名来进一步筛选。
IE4中,标签名必须是大写。

var specialParagraph = document.all["special"];
var buttons = form.all["shippingMethod"]; // May return an array

var specialParagraph = document.all.special;
var buttons = form.all.shippingMethod;

Using the all[] array in this way provides the same basic functionality as getElementById() and getElementsByName().

a tags() method that can be used to obtain an array of elements by tag name.

var lists = document.all.tags("UL"); // Find all <ul> tags in the document
var items = lists[0].all.tags("LI"); // Find all <li> tags in the first <ul>


[quote]Note, however, that in IE 4, the tag name must be specified using all uppercase letters.

The IE 4 HTMLElement object defines setAttribute(), getAttribute(), and removeAttribute() methods as well.
[/quote]

IE4中HTMLElement对象也定义了setAttribute(), getAttribute(), 和removeAttribute()方法。

Modifying Documents
修改文档

IE里面修改文档可以直接通过这几个属性更改文档内容:
innerHTML outerHTML innerText outerText insertAdjacentHTML() insertAdjacentText()

概念和innerHTML类似,这个让然觉得比较疯狂。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JavaScript事件是指在Web页面中,通过JavaScript代码来侦测和响应用户的操作或系统的事件。事件可以是用户的鼠标点击、键盘按键、页面加载完成等等。事件驱动式是指JavaScript代码通过侦测到这些事件,并执行相应的事件处理程序来响应用户的操作或系统的事件。 在JavaScript中,我们可以通过为需要事件处理的DOM元素对象添加事件和事件处理程序来实现事件的绑定。具体的实现方式是,使用DOM元素对象的属性来指定事件,并将对应的事件处理程序赋值给该属性。例如,DOM元素对象.事件 = 事件的处理程序; 在事件绑定过程中,需要注意不同浏览器的兼容性。W3C事件处理函数是符合W3C标准的事件处理方式,适用于大多数现代浏览器。而IE事件处理函数是针对早期版本的IE浏览器的特定事件处理方式。在编写事件处理代码时,根据需求选择合适的事件处理函数进行绑定。此外,还可以通过事件对象来获取事件相关的信息,如事件类型、触发事件的DOM元素等等。 综上所述,JavaScript事件是通过JavaScript代码来侦测和响应用户的操作或系统的事件。我们可以通过为DOM元素对象添加事件和事件处理程序来实现事件的绑定。在实现事件绑定时,需要考虑不同浏览器的兼容性,并选择合适的事件处理函数进行绑定。事件对象可以提供事件相关的信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值