属性节点的属性和方法

这篇博客详细介绍了HTML DOM中的Attr对象和NamedNodeMap对象,包括它们的属性和方法,如Attr的name、value、specified,以及NamedNodeMap的getNamedItem、item、removeNamedItem和setNamedItem等。同时,提到了不同浏览器版本中的一些兼容性问题和注意事项。
摘要由CSDN通过智能技术生成

Attr 对象

在 HTML DOM 中,Attr 对象表示 HTML 属性。

HTML 属性始终属于 HTML 元素。

NamedNodeMap 对象

在 HTML DOM 中,NamedNodeMap 对象表示元素属性节点的无序集合。

NamedNodeMap 中的节点可通过名称或索引(数字)来访问。

浏览器支持
google IE firefox safari opera
true true true true true

属性

1. name

返回属性的名称

浏览器支持
google IE firefox safari opera
true true true true true

DOM.attribute.name || attrObject.name

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>zsh</title>
</head>
<body>
    <div id="div" name="My div"></div>
<script>

    var attr = document.createAttribute('id');
    attr.value = '123';
    console.log(attr.name);

    console.log(div.attributes[1].name);
</script>
</body>
</html>

2. value

设置或返回属性的值

浏览器支持
google IE firefox safari opera
true true true true true

attribute.value = 'something' || attrObject.value

<!doctype html>
<html lang="en">
<head>
    <meta charset=
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值