我正在尝试完成一个项目,需要使用JavaScript实现所见即所得编辑器。由于需要使用自己的插件(例如colorPicker
或imagePicker
),因此无法使用现有的编辑器。
目前,我有以下HTML代码:
<div class="K_editor" id="idExample">
<div class="K_links">
<div class="K_editor_link K_editor_linkBold">B</div>
<div class="K_editor_link K_editor_linkItalic">I</div>
<div class="K_editor_link K_editor_linkUnderline">U</div>
</div>
<iframe width="696" height="212" frameborder="0" src="js/myEditor_iFrame.php">
<html>
<head/>
<body>
<div id="contentIframe" contenteditable="true">
This is a test code, with <strong>bold</strong> text and <em>italic</em> text.
</div>
</body>
</html>
</iframe>
<input type="submit"/>
</div>
当点击 .K_editor_link
时,一个带有参数的函数会被打开:
tagStart
(例如<u>
或<span style="color:#AB1;">
)tagEnd
(例如</u>
或</span>
)id
(此处为idExample
)
我现在可以在 Textarea
上获取选区,但是 setSelectionRange()
、.selectionStart
和 .selectionEnd
只适用于 textbox
(XUL)、input
(XHTML)或 textarea
(XHTML)。
我该怎么办?