JavaScript? CSS ???? ????.
??:
nodeObject.style.cssProperty
? ? nodeObject? ?? ???? cssProperty? CSS ?????.
?:
document.getElementById("demo").style.height; document.getElementById("demo").style.border;
??: "-"? ??? CSS ??? ?? "-"? ???? "-" ?? ? ?? ??? ???? ?????. ?:
background-color? backgroundColor? ???? ???.
line-height? lineHeight? ???? ???.
?:
document.getElementById("demo").style. backgroundColor; document.getElementById("demo").style.lineHeight;
?? ??, ???? ?????. id="demo"? ??:
<div id="demo" style="height:50px; width:250px; margin-top:10px; text-align:center; line-height:50px; background-color:#ccc;"> 點(diǎn)擊這里獲取CSS樣式 </div> <script type="text/javascript"> document.getElementById("demo").onclick=function(){ alert( "高度:"+this.style.height+"\n"+ "寬度:"+this.style.width+"\n"+ "上邊距:"+this.style.marginTop+"\n"+ "對(duì)齊:"+this.style.textAlign+"\n"+ "行高:"+this.style.lineHeight+"\n"+ "背景顏色:"+this.style.backgroundColor ); } </script>
? ??? ?? ???? HTML?? CSS ???? ?????.
<style> #demo{ height:50px; width:250px; margin-top:10px; text-align:center; line-height:50px; background-color:#ccc; } </style> <div id="demo"> 點(diǎn)擊這里獲取CSS樣式 </div> <script type="text/javascript"> document.getElementById("demo").onclick=function(){ alert( "高度:"+this.style.height+"\n"+ "寬度:"+this.style.width+"\n"+ "上邊距:"+this.style.marginTop+"\n"+ "對(duì)齊:"+this.style.textAlign+"\n"+ "行高:"+this.style.lineHeight+"\n"+ "背景顏色:"+this.style.backgroundColor ); } </script>
??? ??? CSS ???? ?? ? ????. HTML ??? CSS ???. ??
nodeObject.style.cssProperty
? DOM ??? style ??? ?? ??? ???? ?? ?????. style ??? ???? ??? style ??? ?? ???? ???? ????. ????? ?? ? ????.
?, JavaScript? ?? ???? ???? ?? <style> ??? CSS ??? ???? ?? ??? ??? ??? ???? ??? ? ????.