【问题标题】:Jquery mouseover not workingJquery鼠标悬停不起作用
【发布时间】:2013-05-11 04:40:09
【问题描述】:

问题是当我点击 li 时,我只显示span 元素,而不是当我将鼠标悬停在li 上时!

我有类似的东西:

       <ul class="nav nav-pills nav-stacked">
        @foreach (var category in Model.Categories)  
     {
        <li class="categoryListEl"><a>@category.Name <span      style="float:right;display:none"class="badge badge-important">
<button class="close">&times;</button></span></a></li>
     }
         </ul>

我的 Jquery 代码是:

 $(function ()
    {
  $(".categoryListEl").mouseover(function () {
           $this = $(this);
          $this.find("span").css("display", "block");
    });
    $(".categoryListEl").mouseleave(function ()
    {
        $this = $(this);
        $this.find("span").hide();

    });;
 );

【问题讨论】:

  • when I click on li not when I hover on li!...点击???你的点击功能在哪里??
  • @bipen 无处,这就是为什么它是奇怪的行为。仅当我单击 li 时才会显示跨度。当我将鼠标悬停在 li 上时,预计会显示 span。
  • 奇怪!!!!确保您没有在代码中的其他任何地方使用此元素...这些代码对我来说看起来不错...
  • 嘿@VladoPandžić,你的问题解决了吗?

标签: jquery mouseover


【解决方案1】:
    $(function ()
        {
      $(".categoryListEl").mouseenter(function () {
               $this = $(this);
              $this.find("span").css("display", "block");
        }).mouseleave(function ()
        {
            $this = $(this);
            $this.find("span").hide();

        });
});

【讨论】:

  • 我遇到了同样的问题,但你的解决方案没有解决。
【解决方案2】:

您的代码中有一些语法错误。你可以试试这段代码,它总是有效的:

$(function () {
    $(".categoryListEl").hover(function () {
        $(this).find("span").toggle();
    });
});

FIDDLE DEMO

【讨论】:

  • 其实我现在看到的都是问题所在。代码仅在 F12 开发人员控制台关闭时才有效。我把它打开了。
  • 酷。终于找到解决方案了!
猜你喜欢
  • 2015-08-08
  • 2011-04-06
  • 2018-11-05
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 1970-01-01
  • 2015-04-04
  • 2011-08-04
相关资源
最近更新 更多