Jquery hover()在悬停时未触发

Jquery hover() not triggering on hover

本文关键字:悬停 hover Jquery      更新时间:2023-09-26

我有一个奇怪的问题。我正在尝试使用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");
        });

它正在工作。(最新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>