尝试在循环中预加载图像,效果很好,但如何用另一个标签包装每个图像。执行此代码将不起作用,而且到目前为止我还没有发现问题。
...
var img = new Image();
$(img).load(function(){
$(this).hide();
$('.container').append('<a href="/">'+this+'</a>'); $(this).fadeIn();
});
...
最佳答案
您是否尝试过使用 $(this) 而不是 this。
或者你为什么不使用:
var $html = $(this).wrap('<a href="/" />');
$('.container').append($html);
关于javascript - 如何用标签包装 var img = new image ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6761705/