Home >Web Front-end >HTML Tutorial >javascriptp operation css_html/css_WEB-ITnose
CSS
Javascript动态操作CSS总结 这次说说javascript。前端三大代码,html、css、javascript(jquery)。我还是想说下css方面的。所以就写个javascript操作css的帖子。javascript也是前端最重要的功能语言,不懂这个真没法混啊~
以前javascript作为脚本语言的时候,主要功能就是操作dom,很多就是操作元素的样式。
大家最熟悉应该就是style属性了。
比如:obj.style.display = "none";
就可以把obj元素隐藏。但是这个style是把代码以内联的形式写进html里面的。读取属性的时候也只能读取内联形式的css。比如:
1.inlineStyle [element’s style attribute]
Whether in ie or ff, element has a style attribute of type Css2Properties, whose attributes correspond to the style attributes in html. These values can The query can also be modified. Note that the values obtained through the style query are all returned in the form of strings. They can only be set to strings in settings, and the corresponding units must be included for the values.
e.style. left = "300px";
var totalMarginWidth = parseInt(e.style.marginLeft) parseInt(e.style.marginRight);
Node understands
<script> <br> //Delete The style sheet element s2 <br> var s2=document.getElementById("s2"); <br> s2.parentNode.removeChild(s2); <br> </script>
element.style. margin = topMargin ”px” rigntMargin ”px” bottomMargin ”px” leftMargin ”px”;
element.style.margin = topMargin ”px” rigntMargin ”px” bottomMargin ”px” leftMargin “px”;
var padding_left = 50;
element.style.left = padding_left “px”;//Don’t forget to add units
var topMargin = 10,rigntMargin = 11,bottomMargin = 12,leftMargin = 13;
element.style.margin = topMargin ”px” rigntMargin ”px” bottomMargin ”px” leftMargin ”px”;
Javascript Sort Table