编辑innerHtml后调整DIV大小的问题

时间:2010-01-21 07:25:34

标签: jquery javascript-events

在对innerHtml进行一些编辑后,我在调整DIV大小时遇到​​了问题,

<div id='resizeme'>Hello ....(some hidden html elements for re size event)</div>

当我编辑文本时,调整大小事件不会触发。我正在使用jQuery。

1 个答案:

答案 0 :(得分:0)

您应该会看到控制台中发生了什么。当一个元素可以调整大小时,会向它添加许多内部元素。 如果更改元素的innerHTML,那么为可调整性而添加的元素也会丢失。所以调整大小是行不通的。尝试如下。

$('.editme').keypress(function(){
    var targetid = event.target.id;
        var txt = $('#addTxtBox1').val();
        var temptxt = $('#temptxt').val(); //take hidden txt value which is reside in div
        $('#temptxt').val(txt); //assign edited value again in hidden variable

        var tempselection = $(this);
        $(tempselection).resizable("destroy"); // remove the resizability from the element

        var temphtml = $(tempselection).html().replace(temptxt,txt);


        $(tempselection).html(temphtml);

      $(tempselection).resizable(); // add the resizability again

});