I有し以下次のHTMLコード: - バルク削除の場合ユーザ挿入されたデータ属性に基づいて、<ins>タグから選択されたテキストを削除
<p class="newPara" id="1_0_1">
<ins data-inserted="1">The ability of </ins><ins data-inserted="2">computers to follow</ins> <ins data-inserted="2">a sequence of operations</ins><ins data-inserted="1">, called a program, </ins><ins data-inserted="2">make computers very flexible and useful.</ins>
</p>
<p class="newPara" id="1_0_2">
<ins data-inserted="1">Peripheral devices</ins> <ins data-inserted="2">include input devices </ins><ins data-inserted="1">(keyboards, mice, joystick, etc.),</ins> <ins data-inserted="2">output devices (monitor screens, printers, etc.),</ins><ins data-inserted="1"> and input/output devices that perform both functions.</ins>
</p>
特定のユーザによって入力されたテキストを削除する必要があり、他のユーザーが入力した残りのテキストは、ストライクスルーモードに変更する必要があり、消えることはありません(delタグへのinsタグ)。これは複数のフラグメントが選択されている場合にも必要です。
これは、バックスペース、削除、選択削除、バックスペースの選択などのすべての使用例で処理する必要があります。
私の予想結果は次のとおりです。 - ユーザーID 1が両方の段落 と押してキーを削除選択されている場合、私は次の出力
<p class="newPara" id="1_0_1">
<ins data-inserted="1">The ability of </ins><del data-deleted="1" data-inserted="2">computers to follow</del> <del data-deleted="1" data-inserted="2">a sequence of operations</del><ins data-inserted="1">, called a program, </ins><del data-deleted="1" data-inserted="2">make computers very flexible and useful.</del>
</p>
<p class="newPara" id="1_0_2">
<ins data-inserted="1">Peripheral devices</ins> <del data-deleted="1" data-inserted="2">include input devices </del><ins data-inserted="1">(keyboards, mice, joystick, etc.),</ins> <del data-deleted="1" data-inserted="2">output devices (monitor screens, printers, etc.),</del><ins data-inserted="1"> and input/output devices that perform both functions.</ins>
</p>
を必要とする私は、次のコードを試してみました1つのnewParaクラスのユーザー変更を追跡するには、次のコードからうまく動作します。
var sel = window.getSelection();
var $parent = $(sel.getRangeAt(0).commonAncestorContainer);
var $clone = $("<div/>").append(sel.getRangeAt(0).cloneContents());
var str = $clone.html();
sel.deleteFromDocument();
var span = document.createElement("div");
$(span).addClass('tempSelectedDiv');
span.innerHTML = str;
sel.getRangeAt(0).insertNode(span);
$.each($('.tempSelectedDiv').contents(), function(i, val) {
if(val.nodeName == 'INS' && val.getAttribute('data-ins-author') == abapp.userId){
val.remove();
}else{
$(val).replaceWith('<del data-ins-author="'+insAuth+'" >' + $(val).text() +'</del>');
}
});
しかし
はjsfiddleで実施例を更新javascriptの選択に基づいて、複数のnewParaクラスのためにこのコードを達成するために私を助けては、その単一newParaクラスのために働いて、同じプリンシパルが複数のパラ(複数newPara)全体に従うべき
リンク: - https://jsfiddle.net/ww81sbcs/