Addclass不是jQuery中的函数

Chr*_*ris 8 html javascript css wordpress jquery

我有一个鼠标悬停功能,应该为我的视口元素添加一个类,但是当我鼠标悬停时我在firebug中出现错误:TypeError:jQuery(...).addclass不是一个函数.

HTML是:

<!DOCTYPE html>
<html>
<head> 
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<title><?php wp_title('|','true','right'); ?><?php bloginfo('name'); ?></title>
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url'     ); ?>" />
<?php wp_head(); ?>
</head>
<body <?php body_class($class); ?>>
<header>
<div class="main-logo">
    <div id="site-title">

    </div><!--.site-title-->
</div><!--main-logo-->

<div class="header-right">
</div><!--header-right-->
</header>

<nav class="main">
<?php wp_nav_menu( array( 'theme_location' => 'main-menu' ) ); ?>
</nav>

<div class="viewport">
<script type="text/javascript"><!--//--><![CDATA[//><!--
jQuery(document).ready(function(jQuery){
jQuery('nav .home a').mouseover(function()
  {
    jQuery('.viewport').addclass('.viewporthome');
  });
});
 //--><!]]></script>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

相关的风格是:

    .viewport
    {
height: 400px;
width: 400px;
position: relative;
top: -90px;
margin: 0 auto;

}

.viewporthome
{
background-image: url('images/Screen2.png');
background-repeat: no-repeat;
background-position: center;
background-attachment: relative;

}
Run Code Online (Sandbox Code Playgroud)

JS文件是:

      var hoverhome = 'url("images/Screen2.png")';
  var empty = '';
  var success = 'SUCCESS!';
  //home
  jQuery('nav .home a').hover(function()
  {
    jQuery('.viewport').css('background-image', hoverhome);

  });
  jQuery('nav .home a').mouseout(function()
  {    
        jQuery('.viewport').css('background-image', empty);
  }); 
Run Code Online (Sandbox Code Playgroud)

Kar*_*non 17

试试这个 :

jQuery('.viewport').addClass('viewporthome');
Run Code Online (Sandbox Code Playgroud)

addClass 需要一个资本"C".

另外,在添加课程时,您不需要输入"." 在字符串或你的班级将..viewporthome.


Cla*_*edi 6

addClass而不是addclass

  • 不,它只是区分大小写:) (8认同)