如何改变使用jQuery页面内嵌样式 [英] how to change the inline style of the page using jquery

查看:194
本文介绍了如何改变使用jQuery页面内嵌样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的页面中内嵌样式为:

I have an inline styles in my page as :

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>:: Inline Style Page ::</title>
<style type="text/css">
    <!--
    body
    {
        background: #fff;
        font: normal 12px Tahoma, Verdana, Arial;
        color: #636363;
    }
    #header
    {
        height: 60px;
    }
    #menu
    {
        background: #fff;
        height: 30px;
    }
    #footer
    {
        height: 50px;
        background: #fff;
    }
    -->
</style>

我需要更新或使用一些样式添加到内联样式jQuery的..

I need to update or add some styles to the inline styles using jquery..

我试图更新使用jQuery的页面/分隔/控件的字体,背景颜色。我有我的内联样式(从数据库加载)为我的网页内容的样式。我的应用程序的用户可以改变一些风格和更新到数据库。

I am trying to update the font, background color of the page/divs/controls using jquery. I will have my inline styles (loaded from database) for the style of my page content. My application's user can change some of the styles and update it back to the database.

它几乎就像创建自定义的页面应用程序(在C#中asp.net的MVC)。

Its almost like creating custom page application(asp.net mvc in c#).

我怎样才能改变内嵌样式使用jQuery的页面呢?或者是有做任何其他有效的方式?

How can i change the inline styles of the page using jquery? or is there any other effective way to do it?

推荐答案

尝试 jQuery.Rule

然后,你会怎么做:

$.rule('body { backgound-color: #ff0000 }').appendTo('style');

到身体的背景颜色改变为眼烧红

to change the background-color of the body to eye burning red.

如果你只是要添加或覆盖您可以使用普通的jQuery到风格属性添加到基于ID /类具体内容具体的事情:

If you just want to add or override specific things you can use regular jQuery to add a style attribute to specific elements based on id/class:

// add to element with id="foo"
$('#foo').attr("style", {backgroundColor: "#ff0000"}) 
// add to ALL elements with class="bar"
$('.bar').attr("style", {backgroundColor: "#ff0000"})

这篇关于如何改变使用jQuery页面内嵌样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆