如何使用css和javascript来创建可变主题 [英] How to make changeable themes using css and javascript

查看:145
本文介绍了如何使用css和javascript来创建可变主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我很熟悉css和javascript,我想知道,如果你能做一个脚本,允许你改变网站使用的样式表。喜欢说你有一个绿色的主题,其中一切都是绿色的阴影,你会使,所以用户可以将其更改为红色与按下一个按钮。

so i am pretty new to css and javascript and i was wondering if you could make a script that allows you to change what stylesheet the site uses. like say you had a green theme where everything was shades of green you would make so the user can change it to red with the press of a button. anyone have any idea how to do this?

推荐答案

您可以为链接标记设置一个Id,并在运行时切换css。

You can set an Id to the link tag and switch the css at runtime.

HTML

<link type="text/css" rel="stylesheet" media="all" href="../green.css" id="theme_css" />

JS

document.getElementById('buttonID').onclick = function () { 
    document.getElementById('theme_css').href = '../red.css';
};

这篇关于如何使用css和javascript来创建可变主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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