添加属性
odiv.setAttribute("title","hello div!");odiv.setAttribute("class","boxClass");odiv.setAttribute("hello","divTag");//自定义属性设(hello="divTag")
获取属性
var v=odiv.getAttribute("hello");console.log(v);//divTagconsole.log(odiv["hello"]);//undefiend
删除属性
odiv.removeAttribute("title");//参数:属性名//路径相关属性var oImg = document.getElementsByTagName("img")[0];var url=oImg.getAttribute("src")console.log(url);//图片相对路径var url2 = oImg.src;console.log(url2);//获取绝对路径
更多专业前端知识,请上 【猿2048】www.mk2048.com