2014-05-01 54 views
0

我遇到了这个奇怪的问题,我希望有人能够提供帮助。函数只在刷新页面时执行,而不是在第一次加载

var k_img = jQuery('#'+c['id']).parents('.PhotoCommentImage').children('.PhotoCommentImg'); 

k_img[0].onload = (function() { 

//these statements only executes when refresh the page, not on first load. 

}); 

我想要做的是在图像加载完成时执行语句。这里奇怪的是这些语句只在我们加载页面时才会执行。如果我们刷新页面,它工作正常。

在此先感谢。

+1

你可以尝试'$(k_img [0])绑定( '负荷',函数(){//});'' – dcclassics

+3

奇怪的这里是这些语句只在我们加载页面时执行。如果我们刷新页面,它工作正常。“什么? – monkeyinsight

+0

创建的ID是第一个加载的,还是会在创建之后? –

回答

1

由于您使用jQuery,请尝试$(k_img[0]).bind('load', function() { // });

+0

谢谢。它解决了这个问题。 –

相关问题