简体   繁体   English

如何使用JQuery更改Css类?

[英]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. 我有一种方法可以在运行时更改css,但如果我正在更改css,那么它将对每个用户生效,如果我将刷新页面,则它再次显示基本页面。

Help me for this problem that if i will change the css then it will take effect only for the same user. 帮助我解决这个问题,如果我将更改css,那么它将只对同一个用户生效。 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. 该插件是为了使用jQuery UI主题而构建的,但可以很容易地适应您自己的基于CSS的主题。 This plugin works with individual user preferences for a particular theme stored in a database, though I suppose you could also use a cookie. 此插件适用于存储在数据库中的特定主题的个人用户首选项,但我想您也可以使用cookie。 the latter would take more customization. 后者需要更多的定制。 You can find more info on my blog, http://farm-fresh-code.blogspot.com . 您可以在我的博客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). 您可以将您的功能/屏幕设计为:1。在创建新用户时,为用户提供默认的基本布局并将其保留在服务器端(您可以在数据库中保存用户首选项)。 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 2.当他更改样式时,更新用户的用户首选项记录/文件3.在加载页面时,检索用户首选项并更改服务器端的css样式

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. 在页面构建时(服务器端)查阅数据库,查找该用户的自定义项,并将所需的CSS应用于该页面。

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. 例如,ASP.NET提供Web部件框架。

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

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