简体   繁体   English

所见即所得,IE最简单的execCommand

[英]WYSIWYG again, IE simplest execCommand

I wrote the simplest WYSIWYG in js/jquery: http://jsfiddle.net/XnSWF/ 我在js / jquery中写了最简单的所见即所得: http : //jsfiddle.net/XnSWF/

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... 在newset Opera 11,Chrome 16,Firefox 9和Safari 5.1上可以完美运行(例如,设置为粗体显示或在所选文本上设置粗体显示),但在IE9中,我无法将粗体设置为所选文本,并且总是在我使用粗体按钮时,这个carret转到第一行到第一个字母...

Why? 为什么?

It's because the selection is destroyed before the click event fires in IE. 这是因为在IE中触发click事件之前,所选内容已被销毁。 You can get round this by using the the mousedown event instead, or (better) by making the button text unselectable: 您可以改用mousedown事件来解决这个问题,或者(更好)使按钮文本不可选择:

$('<li class="wysiwyg-bold"><b unselectable="on">textBold</b></li>')
    .appendTo('.wysiwyg-toolbar');

Live demo: http://jsfiddle.net/XnSWF/1/ 现场演示: http//jsfiddle.net/XnSWF/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM