0

我正在开发一个jQuery 编辑器。我想捕获在 div 中所做的所有更改。
我经历了一些堆栈溢出问题,例如jquery-listen-to-changes-within-a-div-and-act-accordinglyfire-jquery-event-on-div-change
这些问题用于在更改时获取信息发生了,但我需要了解有关在 div 中所做的所有更改的详细信息,例如添加或删除的任何文本以及在什么位置等
。需要位置和值,以便我可以将其用于我的算法

var editorText = $(".jqte_editor").html();
//editorText = "This is a simple editor"
//Convert text into array
var array = editorText.match(/.{1,5}/g);

var newText = "is not";
var position = 2;

//Add new text and again split it if size is more than 5
if(newText.length > 5)
{
    var newArray = abc.match(/.{1,5}/g);

    for(var i=0;i<newArray.length;i++)
    {
            array.splice(position+i, 0, newArray[i]);
    }

    array.splice(pos-1, 1);
}   

console.log("Array after rendering"+array);

所以在这里,如果我可以获得 newText 和位置,我可以轻松更新数组。

4

0 回答 0