简体   繁体   English

如何向body元素添加一些内联样式

[英]How to add some inline style to the body element

I would like to add some inline style like: 我想添加一些内联样式,例如:

style="background: #FFFFFF;

To the body element with jQuery. 使用jQuery的body元素。

Any help is greatly appreciated 任何帮助是极大的赞赏

http://api.jquery.com/css/ http://api.jquery.com/css/

The .css() method is used typically for what you are trying to accomplish. .css()方法通常用于您要完成的任务。

$('body').css({'background':'#fff'});

Hope this helps! 希望这可以帮助!

由于只有一个body元素,因此您可以轻松获得对其的引用,从该元素创建一个jQuery对象,然后使用css方法设置样式:

$(document.body).css('background', '#fff');

you can add style to any element using 您可以使用添加样式到任何元素

$('elementIdOrTagName').css({ background: '#fff', otherProperty: "otherValue" });

so in your case, it is sufficient to do 所以就您而言,这足以

$('body').css({ background: '#fff' });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM