我有一个网站,其中html标签使用css具有背景图像。我创建了一个标签,当你点击它时,html标签背景图片应该通过CSS改变。我正在使用switchClass,但它不起作用。在下面找到我的代码:
<html class="background1">
&#13;
<div id=photoNum>
<a class="photoLink" href="#">1</a>
</div>
&#13;
.background1 {
background: url(Photos/Main.jpg) no-repeat center center fixed;
}
.background2 {
background: url(Photos/Main2.jpg) no-repeat center center fixed;
}
.background3 {
background: url(Photos/Main3.jpg) no-repeat center center fixed;
}
.background4 {
background: url(Photos/Main4.jpg) no-repeat center center fixed;
}
&#13;
<script>
$('.photoLink').on('click', function() {
$('html').switchClass('background1', 'background3');
});
</script>
&#13;
尝试使用toggleClass来检查它是否是语义问题,但是toggleClass是有效的,因此无法找到脚本无效的原因。我在顶部引用了一个jquery库:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
&#13;
感谢您的帮助!
答案 0 :(得分:0)
67vw
标记上没有class
属性。请将其放在html
标记上。
body
&#13;
和
<body class="background1">