DOM屬性的操作

2022-10-09 02:57:15 字數 637 閱讀 7587

dom對元素屬性的操作

1.getattribute

獲取元素屬性值

input.getattribute('type')

12.setattribute

給元素新增屬性值(第乙個引數是屬性名,第二個引數是屬性的值)必須兩個引數

input.setattribute("yes", "ok") //yes=ok

1新增屬性(乙個值)

input.attributes.setnameditem(disabled)

13.createattribute

建立屬性(用變數接收)

var newattribute = document.createattribute('good')

input.setattribute('good', 'ok')12

4.removeattribute

刪除屬性

input.getattributenode("type")

DOM 屬性操作

href title id src classname var link document.getelementbyid link console.log link.href console.log link.title var pic document.getelementbyid pic con...

dom元素屬性操作(常規屬性操作)

注 原生js操作樣式,只能操作元素的行內樣式 1.操作類名稱 console.log btnlist.classname console.log btnlist.name console.log btnlist.id console.log btnlist.style console.log btn...

DOM 中常用的屬性操作

內建 官方提供,直接使用 js屬性 不可見屬性 將元素節點作為物件使用 非內建 自定義,自己寫,官方沒有提供 不能作為物件操作 js屬性 不可見屬性 行內 其實就是內建的html的style屬性的操作 非行內 專用語句 只能獲取不能設定 相容封裝 樣式的操作 標籤的增刪改查 刪除元素節點物件 改 慎...