Style can only get the inline style, if you need to get the current property value of the element you want,
Ie:
You can use object. Currentstyle.width;
Ff:
You can use getComputedStyle (object,false). width;
A function CSS has been created to control the style that provides UI interaction and completes the parameter matching
1<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>5<title>functionCss</title>67<style type= "Text/css" >8div{width:700px;height:400px;background:gray;font-Size:20px;cursor:pointer;}9</style>Ten<script type= "Text/javascript" > OneWindow.onload=function(){ AOdiv=document.getelementsbytagname (' div ') [0]; -Obtn=document.getelementsbytagname (' Input '); -Odiv.innerhtml= "If you don t init the value,you get the current value.<br/>or else,you change it.<br/>re:<b R/>textbox1:width,height,backgroundcolor,fontsize<br/>textbox2:**px,pink,red, #CCC "; the functionCss (obj,attr,value) { - if(odiv.currentstyle) { - if(arguments.length==2) alert (obj.currentstyle[attr]); - Elseobj.style[attr]=Value; + } - Else if(getComputedStyle) { + if(arguments.length==2) alert (getComputedStyle (OBJ,false) [Attr]); A Elseobj.style[attr]=Value; at } - } -obtn[2].onclick=function(){ - if(obtn[0].value) { - if(Obtn[1].value) CSS (odiv,obtn[0].value,obtn[1].value); - ElseCSS (odiv,obtn[0].value); in } - } to } +</script> -<body> the<div></div> *<input type= "text" placeholder= "the attribute to get"/> $<input type= "text" placeholder= "The value to change"/>Panax Notoginseng<input type= "button" value= "Submit" > -</body> the
Day5------------Functioncss