remove()不删除调整大小的图像 [英] remove() not removing a resized image

查看:75
本文介绍了remove()不删除调整大小的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery谈到.remove()方法

jQuery says about the .remove() method

要删除时使用.remove() 元素本身以及其中的所有内容.此外 元素本身,所有绑定的事件和与jQuery数据相关的 元素被删除了.

Use .remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.

但是,如果您将已调整大小的图像周围的ui-wrapper移除(),似乎并非如此. ui包装器内的图像保留在DOM中.在此处 http://jsfiddle.net/stevea/jP6NY/2/中查看jsfiddle.

But if you remove() the ui-wrapper around an image that has resizing, that doesn't seem to be the case. The image inside the ui-wrapper is left in the DOM. See jsfiddle here http://jsfiddle.net/stevea/jP6NY/2/.

那么删除具有调整大小的图像的正确方法是什么?

So what is the proper way to removed an image that has resizing?

$(function(){  
   $('#pelican').resizable({handles : 'ne,se,sw,nw', aspectRatio : true});
 });

$('button#removeImg').click(function() {
    $('.ui-wrapper').remove();
});

谢谢

推荐答案

要删除在调用.resizable期间创建的图像和包装,请使用:

To remove the image and the wrapper that was created during the call to .resizable, use:

$('#pelican').remove();

要仅保留调整图像大小的能力,而使图像保持其调整大小状态,请使用:

To remove just the ability to resize the image, while leaving the image in its resized state, use:

$('.ui-wrapper').remove();

这样做的原因是,jQuery和jQuery UI小部件在对.remove()和可调整大小的析构函数的调用期间进行了一些整理",从而产生了上述行为.

The reason for this is that jQuery and the jQuery UI widgets do some "tidying up" during the calls to .remove(), and the resizable's destructor, producing the behaviour above.

这篇关于remove()不删除调整大小的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆