jQuery hover()不会在悬停时触发

问题描述 投票:0回答:1

我有一个奇怪的问题。我正在尝试使用jquery悬停。但是我无法使其正常工作。我可以让我工作的唯一方法是单击它。有谁可以看到问题所在?HTML部分:

<a class="preview"><img id="EquipmentInfoPanelElementUrl" height="100" width="100" src="temp.png" alt="gallery thumbnail" /></a>

javascript部分:

  $("a.preview").hover(function (e) {
            $("body").append("<p id='preview'><img src='" + $("#EquipmentInfoPanelElementUrl").attr("src") + "' alt='Image preview' /></p>");
            $("#preview").css("top", (e.pageY - 10) + "px").css("left", (e.pageX + 30) + "px").fadeIn("fast");
        },
     function () {
         $("#preview").remove();
     });

        $("a.preview").mousemove(function (e) {
            $("#preview").css("top", (e.pageY - 10) + "px").css("left", (e.pageX + 30) + "px");
        });
javascript jquery html jquery-hover
1个回答
1
投票

正在工作。 (最新的jQuery库)

<!DOCTYPE html>
<html lang="en">

<head>
  <title>jQuery Autocomplete</title>
  <meta charset="utf-8">
  <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(function() {

      $("a.preview").hover(function(e) {
          $("body").append("<p id='preview'><img src='" + $("#EquipmentInfoPanelElementUrl").attr("src") + "' alt='Image preview' /></p>");
          $("#preview").css("top", (e.pageY - 10) + "px").css("left", (e.pageX + 30) + "px").fadeIn("fast");
        },
        function() {
          $("#preview").remove();
        });

      $("a.preview").mousemove(function(e) {
        $("#preview").css("top", (e.pageY - 10) + "px").css("left", (e.pageX + 30) + "px");
      });

    });
  </script>
</head>

<body>
  <a class="preview"><img id="EquipmentInfoPanelElementUrl" height="100" width="100" src="http://placehold.it/100x100" alt="gallery thumbnail" /></a>
</body>

</html>
© www.soinside.com 2019 - 2024. All rights reserved.