【问题标题】:jQuery .load method not firing on IE9jQuery .load 方法未在 IE9 上触发
【发布时间】:2011-07-29 08:57:10
【问题描述】:

我有 4 个 div (class=mydiv),每个都有一个图像,加载方法会在我测试过的所有其他浏览器上触发,但它不会在 IE9.0 上触发。我不知道它是否适用于任何其他 IE。

$.noConflict();

jQuery(document).ready(function(){

    jQuery('.mydiv img').load(function(){

        alert("fired");

    });

});

尝试使用这些 jQuery 版本:

1.4.2
1.5.2
1.6.2
1.5.1rc1

【问题讨论】:

  • 检查prop('complete')是否为真并调用回调。
  • 你想在 img 元素中加载什么?在我看来,您需要重新检查函数的文档; api.jquery.com/load
  • @MrThys 他试图在图像加载时触发一个事件
  • 我认为你做错了,因为我在 IE9 中测试了这个小提琴并且它有效:jsfiddle.net/za9AB
  • @MrThys:这是事件:api.jquery.com/load-event

标签: jquery internet-explorer internet-explorer-9


【解决方案1】:

我遇到了同样的问题并使用以下方法解决了:

if ($.browser.msie && parseInt($.browser.version) < 10) {
    window.onload = new function() {
        console.log('LOADED IE');
    }
} else {
    $(window).load(function(){
        console.log('LOADED');
    })
}

【讨论】:

    【解决方案2】:

    根据 Shankar Cabus 的说法, 您可以通过以下方式修改:

    if ($.browser.msie) { // For IE only
        $('.mydiv img').onload = new function() {
            alert("fired");
        }
    } else {
        $('.mydiv img').load(function(){
            alert("fired");
        })
    }
    

    因为你想在 $('.mydiv img') 加载之后做一些事情,而不是加载窗口。 希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2011-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多