所见即所得,IE最简单的execCommand [英] WYSIWYG again, IE simplest execCommand
问题描述
我用js/jquery写了最简单的所见即所得: http://jsfiddle.net/XnSWF/
I wrote the simplest WYSIWYG in js/jquery: http://jsfiddle.net/XnSWF/
在新版Opera 11,Chrome 16,Firefox 9和Safari 5.1上可以完美地工作(例如,设置为粗体显示或在所选文本上设置粗体显示),但是在IE9中,我无法将粗体显示为所选文本,并且总是在使用时粗体按钮,此carret转到第一行到第一个字母...
Works perfectly (eg. set to write in bold or set bold on selected text) on newset Opera 11, Chrome 16, Firefox 9 and Safari 5.1 but in IE9 I can't set bold to selected text and always when i use bold button, this carret go to first line to first letter...
为什么?
推荐答案
这是因为在click
事件在IE中触发之前,选择已被破坏.您可以通过使用mousedown
事件来解决此问题,或者(更好)通过使按钮文本不可选择来实现:
It's because the selection is destroyed before the click
event fires in IE. You can get round this by using the the mousedown
event instead, or (better) by making the button text unselectable:
$('<li class="wysiwyg-bold"><b unselectable="on">textBold</b></li>')
.appendTo('.wysiwyg-toolbar');
实时演示: http://jsfiddle.net/XnSWF/1/
这篇关于所见即所得,IE最简单的execCommand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!