<div id="box" class="box" title="abc" style="width:100px;height:100px;">123</div>
<script>
var oBox=document.getElementById('box');
//Attribute
console.log(oBox.getAttribute("title"))
console.log(oBox.getAttribute("style")) //width:100px;height:100px;字符串
oBox.setAttribute('name',"haha")
console.log(oBox.getAttribute("name"))
oBox.removeAttribute('name')
//直接oBox.name
console.log(oBox.title)
console.log(oBox.style.width)
//getComputedStyle().width / currentStyle.width 只能获取style属性里面的内容
if(typeof window.getComputedStyle==="function"){
console.log('1'+getComputedStyle(oBox).width)
}else{
console.log('2'+oBox.currentStyle.width)
}
</script>