我有一个 iframe 文本编辑器。对于插入图像,我有一段代码:
.
.
.
var sel = document.getElementById('wysiwygtextfield').contentWindow.getSelection();
// get the first range of the selection (there's almost always only one range)
var range = sel.getRangeAt(0);
// deselect everything
sel.removeAllRanges();
// remove content of current selection from document
range.deleteContents();
// get location of current selection
var container = range.startContainer;
.
.
.
**afterNode = container.childNodes[0];
container.insertBefore(insertNode, afterNode);**
// This does not work
// container.insertAfter(insertNode, afterNode);
问题在于最后两行。我尝试使用insertAfter
,但它似乎不起作用。使用 insert before 它插入所选内容或与其相邻的元素之前。任何让它插入之后的方法。这样,它就好像用户在输入right to left而不是left to right一样。