节点属性的操作
<script>
window.onload = function(){
var eleNode = document.getElementsByTagName("img")[0];
//属性、赋值的两种方法
//1.元素节点.属性或者元素节点[属性]
console.log(eleNode.src);
console.log(eleNode.tagName);
console.log(eleNode["title"]);
console.log(eleNode["className"]);
console.log(eleNode["alt"]);
console.log(eleNode["id"]);
//2.元素节点.方法()
console.log(eleNode.getAttribute("id"));
eleNode.setAttribute("id","你好");
console.log(eleNode["id"]);
eleNode.removeAttribute("id");
console.log(eleNode["id"]);
}
</script>
<img src = "images/H2.jpg" class = "box" title = "图片" alt="不知道" id = "aaa">
测试结果如下: