我刚刚注意到一个问题似乎会影响所有版本的 IE(已测试 7-10),但不会影响 Chrome 或 FF (Windows 7)。当我缓存一个 jquery 对象然后删除其原始目标时,就会出现此问题。
下面的代码实质上是重新排列 div 中的一些图像,使所选图像排在第一位,但我没有使用 holder div,所以这一切都是在原地完成的。我不想通过将 html 转换为字符串来使事情复杂化,我怀疑这可能是一个众所周知的问题,我只是不知道搜索词,所以如果是这样,请赐教!
$lightbox_gallery = $('.gallery-lightbox .lightbox-gallery');
$image = $lightbox_gallery.find('img[data-id=' + image.id + ']').parent();
$image_after = $image.nextAll();
$image_before = $lightbox_gallery.find('> div:first').nextUntil($image);
console.log($image.html()); //returns a string
$lightbox_gallery.html('');
console.log($image.html()); //returns ''
// this works fine in almost anything but IE. Maybe also safari on mac?
$lightbox_gallery.append($image).append($image_after).append($image_before);
编辑: 使用克隆函数解决了它 http://jsfiddle.net/27DKZ/4/
最佳答案
您的 HTML 是什么样的?我从未见过这样的问题。请记住,IE 无法处理 console.log() 函数。
关于javascript - jQuery 和 IE7+ 缓存 $objects 的意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17636699/