5.21

DOM对元素属性的操作
1.getAttribute
获取元素属性值

input.getAttribute('type')
1
2.setAttribute
给元素添加属性值(第一个参数是属性名,第二个参数是属性的值)必须两个参数

input.setAttribute("yes", "ok") //yes=ok
1
添加属性(一个值)

input.attributes.setNamedItem(disabled)
1
3.createAttribute
创建属性(用变量接收)

var NewAttribute = document.createAttribute('good')
input.setAttribute('good', 'ok')
1
2
4.removeAttribute
删除属性

input.getAttributeNode("type")

posted @ 2022-06-14 22:46  _Pi  阅读(81)  评论(0)    收藏  举报