我正在尝试使用document.getSelection为所见即所得编辑器选择在文本区输入的文本。但是,只有当您选择文本区域之外的文本时,它才起作用。我不知道是否有一种方法可以让它在文本区域内选择文本?
下面是WYSIWYG文本编辑器的文本区域:
<iframe id="editor" width="100%" height="400px" contentEditable="true"></iframe>发布于 2010-08-22 04:25:55
您需要获取iframe文档的选择:
var ifrDoc = document.getElementById("editor").contentWindow.document,
sel = ifrDoc.getSelection();请注意,对于Internet Explorer,您需要document.selection.createRange()而不是document.getSelection()。
https://stackoverflow.com/questions/3538798
复制相似问题