css style operation
css() style operation features: ① Style acquisition, jquery can obtain inline, Interior and exterior styles.
The dom method can only obtain inline styles
② Composite attribute styles need to be split into "specific styles" before they can be operated
For example: background needs to be split into background-color background-image, etc. for operation
border: border-left-style border-left-width border-left-color, etc.
margin: margin-left, margin-top, etc.
<!DOCTYPE html> <html> <head> <title>php.cn</title> <meta charset="utf-8" /> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> function f1(){ alert($('div').css('background-color')); } function f2(){ $('div').css('background-color','red') } function f3(){ var jn={'width':'300px','height':'300px'}; $('div').css(jn); } </script> </head> <body> <div style="width:200px; height:150px; background-color:lightblue;">欢迎大家学习jQuery</div> <input type="button" value="获取背景色" onclick="f1()" /> <input type="button" value="设置背景色" onclick="f2()" /> <input type="button" value="批量设置" onclick="f3()" /> </body> </html>