属性操作
添加属性 - 标签.setAttribute(属性名,属性值)
var div = document.querySelector("div"); console.log(div); div.setAttribute('name','aaa') div.setAttribute('name','bbb')
删除属性 - removeAttribute(属性名)
div.removeAttribute('name') //接上面代码
获取属性的值 - getAttribute(属性名)
var n = div.getAttribute('name') console.log(n); //接上面代码
不体现在标签上的 - .
var input = document.querySelector("input"); //标签复选框默认选中的两种方法: input.checked = true input.checked = false; //不体现在标签上 input.setAttribute('checked','checked') input.removeAttribute('checked') //体现在标签上
注意:一般checked属性和img的src属性都可以使用 . 来操作 ,而.这种操作不体现在标签上的

浙公网安备 33010602011771号