从index.html更改样式表 [英] Changing the stylesheet from index.html
本文介绍了从index.html更改样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试实现用户更改我的PhoneJS应用中主题的功能(可能也是常规JS)。
I'm trying to implement the ability for a User to change theme in my PhoneJS app (might as well be regular JS).
我尝试了什么:
Index.html
<!DOCTYPE html>
<html>
<head>
<link id="style" rel="stylesheet" type="text/css" href="red-stylesheet.css" />
</head>
</html>
Javascript
function swapStyle(sheet) {
document.getElementById('#style').setAttribute('href', sheet);
}
其中表
是 blue-stylesheet.css
或 red-stylesheet.css
,但我一直收到此错误:
Where sheet
is either blue-stylesheet.css
or red-stylesheet.css
, but I keep getting this error:
对于未定义或空值的引用,不能设置'setAttribute'
Cannot 'setAttribute' for a reference that's undefined or null
所以我猜我无法从我的index.html访问该链接
So I'm guessing that I can't access the link from my index.html
这是我的文件结构:
views (folder)
-> settings (folder)
-> settings.js (javascript)
index.html (html with the <link>)
推荐答案
你的Javascript只是一点点。 Theres不需要选择器中的#
。
Your Javascript is just a little out. Theres no need for the #
in the selector.
function swapStyle(sheet) {
document.getElementById('style').setAttribute('href', sheet);
}
这篇关于从index.html更改样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文