Jquery UI添加不必要的代码和破坏的东西

jquery ui adding unnecessary code and breaking things

本文关键字:代码 UI 添加 不必要 Jquery      更新时间:2023-09-26

我一直在使用本地存储保存一个调整大小的元素

加载页面时,UI代码被添加到resizediv中。一开始你可以调整元素的大小,但如果你保存它并刷新页面,ui代码会再次添加,这会破坏它。我知道我可以在保存之前运行replace,但是我想知道是否有其他更有效的方法。

代码添加了不止一次。
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" );