在 contenteditable div 中的选定文本上添加跨度

发布于 2024-10-07 04:35:36 字数 272 浏览 0 评论 0原文

我希望用户能够选择 div 中的文本并向其添加

示例代码 @ http://jsfiddle.net/SkDA8/1/

将鼠标悬停在 div 上并单击缺少图片来显示色样

感谢您的帮助!

PS

我希望它能在所有现代浏览器中工作。

I want the user to be able to select the text in the div and add the <span style="color: #ff3300;"> to it.

Example code @ http://jsfiddle.net/SkDA8/1/

Hover over to div and click on the missing picture to display the color-swatch

Thanks for your help!

PS

I want it to work in all modern browsers.

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

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

发布评论

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

评论(2

无需解释 2024-10-14 04:35:36

我正要回复你在 Rangy 小组上发表的有关此事的帖子,但我也会在这里回复。

这是可以使用 document.execCommand() 实现的一项任务:

document.execCommand("ForeColor", false, "#ff3300")

我已经为您的 jsfiddle 创建了更新:

I was about to respond to your post to the Rangy group about this, but I'll respond here too.

This is one task that is achievable using document.execCommand():

document.execCommand("ForeColor", false, "#ff3300")

I've created an update to your jsfiddle: http://jsfiddle.net/timdown/SkDA8/3/

差↓一点笑了 2024-10-14 04:35:36

不太确定你想做什么。这是一个更新的 jsFiddle,它获取单击的彩色样本的值并更新标题颜色。

http://jsfiddle.net/SkDA8/4/

希望这会有所帮助。

鲍勃

Not exactly certain what you are trying to do. Here is an updated jsFiddle that gets the value of the colored swatch that is clicked and updates the header color.

http://jsfiddle.net/SkDA8/4/

Hope this helps.

Bob

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