簡體   English   中英

Jquery hover() 不會在懸停時觸發

[英]Jquery hover() not triggering on hover

我有一個奇怪的問題。 我正在嘗試使用 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM