【问题标题】:jquery - onmouseover and onmouseoutjquery - onmouseover 和 onmouseout
【发布时间】:2012-10-08 07:51:48
【问题描述】:

当鼠标悬停/移出时,我试图显示/隐藏上一个/下一个按钮。但它似乎没有工作。我的代码有什么问题吗?

这是我的代码。

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Portfolio</title>
      <link rel="stylesheet" href="css/global.css">

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
  <script src="js/jquery.easing.1.3.js"></script>
  <script src="js/slides.jquery.js"></script>
  <script>


       $('.eachImage').on( "mouseover", function() {
         $('#prevButton').show();
       });
        </script>

      </head>

      <body bgcolor="#FFFFFF">

        <div id="container">
    <div id="example">
        <div id="slides">
            <div class="slides_container">
                <img src="imgs/test.png" width="800" height="456" class="eachImage">
            </div>
            <div id="prevButton"><a href="#" class="prev"><img src="imgs/arrow-prev.png" width="24" height="43" alt="Arrow Prev"></a></div>
            <div id="nextButton"><a href="#" class="next"><img src="imgs/arrow-next.png" width="24" height="43" alt="Arrow Next"></a></div>
        </div>
    </div>
        </div></body>
      </html>

谢谢。

【问题讨论】:

  • 你能定义“不工作”吗?
  • 另外,你可以简单地使用.hover ;)
  • &lt;div id="prevButton"&gt;&lt;div class="nextButton" 你混合 ids/classes,坏主意
  • 我编辑了描述。我复制并粘贴了整个文件。

标签: jquery


【解决方案1】:

这是要使用的功能

 $(document).ready(function(){
     $('.eachImage').mouseover(function(){
    $('#prevButton').toggle();
    });
     });

我还包括一个 jsfiddle

http://jsfiddle.net/joseluisrod/XwMzh/3/

关键是每个按钮都有 style="display:block"

【讨论】:

  • 好的,你检查了 jsFiddle。它在那里工作吗?将代码包含在 document.ready 中并具有用于显示的 css 样式也非常重要。你收到错误消息了吗?
猜你喜欢
  • 2023-03-03
  • 1970-01-01
  • 1970-01-01
  • 2012-02-04
  • 2015-08-27
  • 1970-01-01
  • 2014-07-21
  • 2011-06-27
  • 2012-12-12
相关资源
最近更新 更多