我做了一个小功能,从我的集线器的黑暗版本切换到轻型版本。但是,我的代码无效,我检查了控制台并且没有记录任何错误。
有人能帮我发现问题吗?我是一个菜鸟和jQuery / Javascript的新手。当我点击链接时,它什么都不做,也没有产生错误。
这是代码:
<li>
<a id="switch-theme" href="#" rel="tooltip" title="Change style" onclick="return false;">
<i class="fa fa-paint-brush"></i>
</a>
</li>
<script>
currentTheme = localStorage['theme'];
if(currentTheme == null) //theme isn't set, just set it to dark.
currentTheme = "dark";
function themeHandler() {
$("head link#theme-stylesheet").attr("href", "includes/frontend/theme/bootstrap-" + currentTheme + ".min.css");
//handle theme switching.
$("#switch-theme").click(function() {
var theme = "dark";
if(currentTheme == "dark") {
theme = "light";
}
localStorage['theme'] = theme;
currentTheme = theme;
$("head link#theme-stylesheet").attr("href", "includes/frontend/theme/bootstrap-" + theme + ".min.css");
});
//we just want the current theme.
return false;
}
$(document).ready(function() {
$("[rel=tooltip]").tooltip();
themeHandler();
});
</script>
我需要做些什么来使我的工作符合预期?