1

为选定文本创建的跨度标签,那么如何在跨度标签内为选定文本附加 div?

我的代码如下:

function surroundRangeNote() {
            var range = getFirstRange(); //get selected text

                var el = document.createElement("span");

                el.style.backgroundColor = "#E3F6CE";
}
$(function() {
    $("#pin").on('tap', function() { 
                        var timestamp = Number(new Date());

                        var div =document.createElement("div");
                        div.className="note_main";
                        var button=div.appendChild( document.createElement("button") );
                        button.setAttribute("onclick", "return run("+timestamp+");");
                        var child=div.appendChild( document.createElement("div") );
                        child.id='diva'+timestamp;
                        child.setAttribute("style", "display:none");
                        child.className="note_sub";
                        var subchild=child.appendChild( document.createElement("input") );
                        subchild.setAttribute("style", "background:#C9C ");
                        subchild.id='text'+timestamp;
                        subchild.setAttribute("onchange", "return save_me("+timestamp+");");

                        var subchild2=child.appendChild( document.createElement("input") );
                        subchild2.setAttribute("type", "hidden");
                        subchild2.setAttribute("value", "");
                        subchild2.id='hidden'+timestamp;
                        var sel = rangy.getSelection();
                        if (sel.rangeCount > 0) {
                            var range = sel.getRangeAt(0);
                            range.collapse(false);
                            range.insertNode(div);
                            surroundRangeNote();
                        }
                    });
          });

输出:<span style="background-color: rgb(227, 246, 206);">release </span><div> </div> 在创建我的 div 之后,

但是如何在 span 标签中创建这个 div?喜欢

<span style="background-color: rgb(227, 246, 206);">release <div> </div> </span>
4

0 回答 0