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

发布于 2024-12-29 14:47:21 字数 262 浏览 4 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌能量女王 2025-01-05 14:47:21

这是因为在 IE 中触发 click 事件之前,选择内容已被销毁。您可以通过使用 mousedown 事件来解决此问题,或者(更好)通过使按钮文本不可选择:

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

实时演示: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 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');

Live demo: http://jsfiddle.net/XnSWF/1/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文