/*set/getAttribute()
removeAttribute
【注】都是操作当前元素节点中某个属性*/
window.onload=function () {
var odiv=document.getElementById("div1");
alert(odiv.title);//alert(odiv.getAttribute("title"));
alert(odiv.className);
odiv.title="xxx";//改变其中内容
odiv.setAttribute("title","xxx");//设置内容
/*上述两种方式区别
1、class访问有区别的,点操作是通过className
而set/getAttribute是通过class
2、set/getAttribute支持用户自定义属性
3、removeAttribute*/
alert(odiv.getAttribute("class"));
//设置用户自定义属性
odiv.xxx="yyy";//与下面设置不成功
odiv.setAttribute("xxx","yyy");
alert(odiv.xxx);//与下面相比访问不到
alert(odiv.getAttribute("xxx"));
odiv.removeAttribute("title");//可以修改
odiv.title="";//不能修改
}
</script>