Javascript 只有在前面放置了一个alert()时,jQuery才会起作用

Javascript 只有在前面放置了一个alert()时,jQuery才会起作用,javascript,jquery,elevatezoom,Javascript,Jquery,Elevatezoom,我有这段代码要启动jQuery-elevateToom,但是,只有在前面放置了alert()时,这段代码才有效 我已经尝试过使用/不使用load()函数 jQuery(document).ready(function($){ alert("Hi"); $("#sh-product-main-image").load(function(){ $(this).elevateZoom({ zoomType: "inner",

我有这段代码要启动jQuery-elevateToom,但是,只有在前面放置了
alert()
时,这段代码才有效

我已经尝试过使用/不使用
load()
函数

jQuery(document).ready(function($){
    alert("Hi");
    $("#sh-product-main-image").load(function(){
        $(this).elevateZoom({
            zoomType: "inner",
            debug : true,
            cursor: "crosshair", 
            zoomWindowFadeIn: 500,
            zoomWindowFadeOut: 500
        }); 
    }); 
});
这是我尝试过的代码的另一个变体:

jQuery(document).ready(function($){
    alert("Hi");
    $("#sh-product-main-image").elevateZoom({
        zoomType: "inner",
        debug : true,
        cursor: "crosshair", 
        zoomWindowFadeIn: 500,
        zoomWindowFadeOut: 500
    }); 
});
这是因为加载DOM时会发生
$(document).ready()
,而不是加载所有图像时。该警报会导致延迟,并允许有时间加载图像

以下方面应起作用:

$(window).on("load", function() {
    $("#sh-product-main-image").elevateZoom({
        zoomType: "inner",
        debug : true,
        cursor: "crosshair", 
        zoomWindowFadeIn: 500,
        zoomWindowFadeOut: 500
    }); 
});

我认为ElevateToom插件需要完全加载DOM才能正常工作,而不是页面加载!(通常建议DOM加载超过页面加载!)

我认为下面的代码就足够了:

$(function() { /* Executed after DOM did load */

  $("img#sh-product-main-image").elevateZoom({
    zoomType: "inner",
    debug : true,
    cursor: "crosshair", 
    zoomWindowFadeIn: 500,
    zoomWindowFadeOut: 500
  });

});