gpt4 book ai didi

javascript - webkit stylewithcss contenteditable 不工作?

转载 作者:数据小太阳 更新时间:2023-10-29 05:46:02 25 4
gpt4 key购买 nike

我正在尝试使用 contenteditable 和 styleWithCss。

在webkit中好像不行。

每当我使用 execCommand 时,它都会生成一个 <b>而不是我预期的跨度。

这是一个演示: http://jsbin.com/izomo/2/edit

选择部分文本,单击粗体按钮,然后查看 html 输出。

这是一个错误还是我做错了什么。

非常感谢。

最佳答案

我无法让它与此处两个答案中的命令一起使用。对于那些仍在为这个问题苦思冥想的人,这是如何让它发挥作用的。

我们可以将三个值传递给 execCommand

document.execCommand( command, uiElement, value ) 

正如 Christopher 的优秀答案所详述的那样,“styleWithCSS”的值默认设置为 false试试看:

alert(document.queryCommandState("styleWithCss"));

要将其设置为 true,您需要将第三个参数“value”作为 true 传递。像这样:

document.execCommand("styleWithCSS", null, true);

这适用于 Firefox 和 Chrome

关于javascript - webkit stylewithcss contenteditable 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3088993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com