我有以下SPAN包含另一个动态添加的SPAN。
我正在更改跨度的光标,但它仍然是默认光标,是否可以不更改?
<span class="content" id="message" contenteditable="true">
This is a sample message <span class="nonEditable" style="cursor: pointer;"><#TimeOfDay> <span onclick="removePlaceholder(this)"/>
<span class="closeTag">X</span>
</span>
</span>
这是将HTML添加到SPAN的代码
function pasteHtmlAtCaret(html) {
var btnValue = html.value;
//var span = " <span class='nonEditable tags'>" + btnValue + "<span class='testing' cursor='pointer'></span>X</span> ";
var span = '<span class="nonEditable" style="cursor: pointer" ><#' + btnValue + '> <span onclick=removePlaceholder(this)></span><span class="closeTag">X</span></span> ';
var sel, range;
if (window.getSelection) {
// IE9 and non-IE
sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
range = sel.getRangeAt(0);
range.deleteContents();
// Range.createContextualFragment() would be useful here but is
// non-standard and not supported in all browsers (IE9, for one)
var el = document.createElement("div");
el.innerHTML = span;
var frag = document.createDocumentFragment(), node, lastNode;
while ((node = el.firstChild)) {
lastNode = frag.appendChild(node);
}
range.insertNode(frag);
// Preserve the selection
if (lastNode) {
range = range.cloneRange();
range.setStartAfter(lastNode);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
}
}
} else if (document.selection && document.selection.type != "Control") {
// IE < 9
document.selection.createRange().pasteHTML(span);
}
}