javascript - jquery ui 添加不必要的代码和破坏东西

标签 javascript jquery

好的,所以我一直致力于使用本地存储来保存调整大小的元素

当您加载页面时,ui 代码会添加到调整大小的 div 中。 起初您可以调整元素的大小,但如果您保存它并刷新页面,则会再次添加调整大小的 ui 代码,这会破坏它。我知道我可以在保存之前运行替换,但我想知道是否还有其他更有效的方法。

代码添加了不止一次。
http://jsfiddle.net/code_cookies/Spkzq/95/

<div class="ui-resizable-handle ui-resizable-e" style="z-index: 1000;"></div>
<div class="ui-resizable-handle ui-resizable-s" style="z-index: 1000;"></div>
<div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se"     style="z-index: 1000;"></div>

JS:

if (localStorage.pins === "") { 
    $('#draggable').html('<div id="image"class="resize" style="padding:20px; width:200px; height:200px; background-color:white;"><img class="" width="100%" height="100%" src="http://i48.tinypic.com/31368e9.jpg"/></div>');
}
else { 
    $('#draggable').html(localStorage.pins);
}
$("#image").resizable();
$('#save').click(function() {
    localStorage.pins = $('#draggable').html();
});

最佳答案

您可以通过调用 destroy 删除 jquery UI 添加的所有内容:

$("#image").resizable( "destroy" );

关于javascript - jquery ui 添加不必要的代码和破坏东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16490140/

相关文章:

javascript - @angular/pwa service worker 没有在我已经存在的项目上工作

javascript - 如何替换 html 内容中的两个类属性?

php - 显示 jquery ajax 执行状态

javascript - swiper js自动设置每个 View 的幻灯片数量

javascript - 在 JavaScript 中检测字符串中的阿拉伯字符数

javascript - 检查一个javascript数组是否包含另一个数组的所有元素或部分元素值

javascript - 在 JavaScript 中将倒计时日期格式转换为毫秒

javascript - Jquery 时间轴插件

javascript - 是否有其他方法使用 Jquery 删除父表行和子表行

javascript - 在 wordpress 页面上将所有出现的 "http"更改为 "https"