再次所见即所得,IE最简单的execCommand
我在js/jquery中编写了最简单的所见即所得: http://jsfiddle.net/XnSWF/
完美运行(例如在新版 Opera 11、Chrome 16、Firefox 9 和 Safari 5.1 上设置为以粗体书写或在所选文本上设置粗体,但在 IE9 中我无法将所选文本设置为粗体。当我使用粗体按钮时,这个插入符会转到第一行第一个字母...
为什么?
I wrote the simplest WYSIWYG in 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...
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为在 IE 中触发
click
事件之前,选择内容已被销毁。您可以通过使用mousedown
事件来解决此问题,或者(更好)通过使按钮文本不可选择:实时演示:http://jsfiddle.net/XnSWF/1/
It's because the selection is destroyed before the
click
event fires in IE. You can get round this by using the themousedown
event instead, or (better) by making the button text unselectable:Live demo: http://jsfiddle.net/XnSWF/1/