每天固定就好
2016-10-24 19:50:13
<!DOCTYPE html><html><head>? ? <meta charset="UTF-8">? ? <title>Title</title>? ? <style type="text/css">? ? ? ? *{? ? ? ? ? ? margin: 0;? ? ? ? ? ? padding: 0;? ? ? ? }? ? ? ? div {? ? ? ? ? ? width: 1000px;? ? ? ? ? ? height: 300px;? ? ? ? ? ? text-align: center;? ? ? ? ? ? background: #0e90d2;? ? ? ? ? ? color: #d3eff9;? ? ? ? ? ? font-family: '微軟雅黑';? ? ? ? ? ? line-height: 300px;? ? ? ? }? ? ? ? p {? ? ? ? ? ? font-size: 20px;? ? ? ? }?.answer{display:none;}? ? </style></head><body><div>? ? <p>鼠標經(jīng)過文字將會縮放</p></div><script type="text/javascript">window.onload=function(){? div=document.getElementsByTagName("div")[0];? div.onmouseover=function(){? ? ?startMove();? }}function startMove(){//情況一:尚未改變div的樣式,不能夠獲取非內(nèi)聯(lián)樣式alert(div.style.width);/*情況二:改變了div的樣式,能夠獲取非內(nèi)聯(lián)樣式div.style.width=300+"px";alert(div.style.width);*/}</script></body></html>
3 回答


千秋此意
TA貢獻158條經(jīng)驗 獲得超188個贊
.style只能獲取內(nèi)聯(lián)樣式,設置樣式也是內(nèi)聯(lián)的
獲取非內(nèi)聯(lián)的方法:
/** ?*?div.currentStyle?兼容ie ?*?window.getComputedStyle?firefox?chrome等 ?*?以上返回一個CSSStyleDeclaration對象,即一個css樣式的鍵值對集合 ?*/ var?width?=?(div.currentStyle?||?getComputedStyle(div,?null))['width'];
添加回答
舉報
0/150
提交
取消