javascript - 如何让一个按钮改变两个样式表

标签 javascript html css stylesheet

大家好,stackoverflow 论坛的各位。

所以在我的网站上,我添加了更改布局颜色的选项,我想将标题更改为,但我不知道如何更改。我正在使用的代码是在 javascript 中,我正在使用按钮在样式表之间进行更改。现在我的问题是如何让一个按钮一次单击更改两个样式表。页眉样式表相当大,我希望它与其他样式分开。

我从哪里得到代码:

-LINK-


javascript:

<script type="text/javascript">
function swapStyleSheet(sheet){
     document.getElementById('pagestyle').setAttribute('href',sheet);
}
</script>

HTML:

负责人:

<link id="pagestyle" rel="stylesheet" type="text/css" href="css/index/index_purple.css" media="screen"/>

正文:

<button onClick="swapStyleSheet('css/index/index_purple.css')">Purple style</button>

<button onClick="swapStyleSheet('css/index/index_orange.css')">Orange style</button>

<button onClick="swapStyleSheet('css/index/index_blue.css')">Blue style</button>

<button onClick="swapStyleSheet('css/index/index_red.css')">Red style</button>


我的页面:

-LINK-

最佳答案

有什么理由不尝试多次使用JS中的命令吗?

<script type="text/javascript">
    function swapStyleSheet(pagesheet, headsheet){
        document.getElementById('pagestyle').setAttribute('href',pagesheet);
        document.getElementById('headstyle').setAttribute('href',headsheet);
    }
</script>

按钮定义为

<button onClick="swapStyleSheet('css/index/index_purple.css','css/head/head_purple.css')">Purple style</button>

关于javascript - 如何让一个按钮改变两个样式表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16428932/

相关文章:

javascript - 单击提交按钮时如何仅加载内容区域?

html - 防止弹出窗口透明

html - 相对包装器中的 CSS 中心内容

javascript - 在 JavaScript 中捕获类内部调用者的 `this`

javascript - Google chrome 是否支持自定义 MIME 类型?

javascript - 数组之间的对称差异

javascript - 单击所有单选按钮显示 div

javascript - 如何在 Node 中注册和使用 Handlebars 助手?

javascript - 如何将 span 包裹在一段 HTML 中?

html - 使整个页面可扩展