jquery中的switchClass不起作用

时间:2015-08-23 23:27:22

标签: jquery html css

我有一个网站,其中html标签使用css具有背景图像。我创建了一个标签,当你点击它时,html标签背景图片应该通过CSS改变。我正在使用switchClass,但它不起作用。在下面找到我的代码:

  1. line:
  2. 
    
    <html class="background1">
    &#13;
    &#13;
    &#13;

    1. 带有触发jQuery的链接:
    2. &#13;
      &#13;
      <div id=photoNum>
          <a class="photoLink" href="#">1</a>
        </div>
      &#13;
      &#13;
      &#13;

      1. CSS:
      2. &#13;
        &#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;
        &#13;
        &#13;

        1. jquery脚本:
        2. &#13;
          &#13;
          <script>
              $('.photoLink').on('click', function() {
                $('html').switchClass('background1', 'background3');
              });
            </script>
          &#13;
          &#13;
          &#13;

          尝试使用toggleClass来检查它是否是语义问题,但是toggleClass是有效的,因此无法找到脚本无效的原因。我在顶部引用了一个jquery库:

          &#13;
          &#13;
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
          &#13;
          &#13;
          &#13;

          感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

67vw标记上没有class属性。请将其放在html标记上。

&#13;
&#13;
body
&#13;
&#13;
&#13;

<body class="background1">