简体   繁体   中英

How to change Css class using JQuery?

I have an multi user application with basic layouts where i want to change the layout and style of the page for individual user .

I have one way in mind that to change the css at run time but if i am changing the css then it will take effect for every user and if i will refresh the page then it shows basic page again.

Help me for this problem that if i will change the css then it will take effect only for the same user. and it will not change after refresh.

Or any buddy has any other idea then please suggest me.

$("div#somediv").addClass("specialuserclass");

JQuery引用或每个用户都有一个样式表;

You might be interested in doing this using themes and the theme manager plugin I built. The plugin is built to work with jQuery UI themes, but could easily be adapted to your own custom CSS-based themes. This plugin works with individual user preferences for a particular theme stored in a database, though I suppose you could also use a cookie. the latter would take more customization. You can find more info on my blog, http://farm-fresh-code.blogspot.com .

You have to persist the style chosen by each user.

Your can design your function/screen to something like: 1. On create of a new user, give the user the default basic layout and persist this in the server side (you can probably save the user preference in your DB). 2. When he changes style, update the user's user preference record/file 3. On load of the page, retrieve the user preference and change the css style on the server side

If you want to implement this yourself, store your user-specific styles in a dedicated store such as a database, indexed by user. At page construction time (server side) consult your database, looking up the customizations for that user, and apply the CSS you want to that page.

Alternatively there are a variety of theming applications available. These will depend on your server-side tools. For example, ASP.NET offers the Web Parts Framework.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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