选择文本时使鼠标单击无响应

发布于 2024-09-17 06:02:33 字数 209 浏览 3 评论 0原文

我目前正在开发 WYSIWYG 网页编辑器。

我遇到的问题有点复杂。

当我选择一段文本并单击工具上的某些内容时,该命令有效,但文本立即变为未选中状态。

就像我们在任何网页中选择文本一样,当我们点击其他内容时,文本就会变为未选中状态,一切恢复正常。

当已经选择文本时,有没有办法抑制鼠标点击,以便文本保持选中状态?

提前致谢。

I am currently working on a WYSIWYG web editor.

The problem i ran into is a little complicated.

When I select a section of text and click on something on my tools, the command works but immediately the text becomes unselected.

Just like when we select text in any webpage, when we click on something else, the text becomes unselected and everything returns to normal.

Is there a way to suppress the mouse clicks when a text is already selected so that the text will remain selected?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

奶茶白久 2024-09-24 06:02:33

您需要向工具栏中的所有 html 元素添加一个属性:

unselectable = "on"

这适用于 IE,不知道是否适用于其他浏览器。
我记得当我尝试通过第 n 个所见即所得 HTML 编辑器来重新发明轮子时。
当我决定使用TinyMCE后,即使有时我仍然后悔没有从头开始开发它的乐趣

You need to add an attribute to all html elements in the toolbar:

unselectable = "on"

This works for IE, don't know for other browsres.
I remember this from when i was playing with attempting to the reinvent teh wheel by doing the nth WYSIWYG HTML editor.
After I decied to use TinyMCE, even if sometimes I still regret not to have fun in developing it from scratch

夜清冷一曲。 2024-09-24 06:02:33

在相关元素上添加一个事件侦听器,并使函数返回 false - 这将捕获默认行为(即取消选择文本)。您需要将 useCapture 设置为 true 才能使其工作。

Add an event listener on the elements in question, and make the function return false - this will catch the default behaviour (which is unselecting your text). You'll need to set useCapture to true for this to work.

温柔一刀 2024-09-24 06:02:33

当您添加 unselection=on 时,工具栏元素单击将不起作用。这个问题是IE特有的,
IE 在工具栏上越过时调整手柄插入符的大小

When you add unselection=on then toolbar element click will not work. this problem is specific to IE,
IE Resize Handle Caret when get over on toolbar

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