简体   繁体   English

为什么该功能没有运行?

[英]Why isn't this function running?

  $('.posts li img').each(function() {
    if( this.complete )
      imageResize($(this), 64, 64);
    else
      $(this).load(imageResize($(this), 64, 64));
  });

I tried adding "alert('test')" to imageResize(), but it isn't working. 我尝试在imageResize()中添加“ alert('test')”,但无法正常工作。 Is there any reason why imageResize() isn't being called? 有什么原因为什么没有调用imageResize()?

使其功能:

$(this).load(function(this) {imageResize(this, 64, 64)});

Not sure that this is the problem, but it's certainly a potential problem. 不确定这是问题所在,但肯定是潜在问题。 The second imageResize() call will be executed immediately and the return code used as the handler for the load event. 第二个imageResize()调用将立即执行,并将返回代码用作load事件的处理程序。 You need to wrap it in an anonymous function and use that instead, eg 您需要将其包装在一个匿名函数中,并使用它,例如

  $('.posts li img').each(function() {
    if( this.complete )
      imageResize($(this), 64, 64);
    else
      $(this).load(function() {imageResize($(this), 64, 64);});
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM