为所选文本创建的跨度标记,那么如何在span标记中为选定文本附加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>