通过 JavaScript 从 CKEditor 中的样式框中分配一些样式
如何通过 JS 模拟用户从样式框中选择某种样式?我想放一些快捷按钮,一键分配一些流行的样式。
编辑:
- 我不在乎它是编辑器内按钮还是外部按钮。
- 我不想要 css-style 分配;我想要 CKEditor 风格 分配(样式框的分配)。
How can I simulate user-selection of some style from the styles-box, through JS? I want to put some shortcut buttons that assign some of the popular styles with one click.
EDIT:
- I don't care if it'll be in-editor button or outer button.
- I don't want css-style assignment; I want CKEditor-style assignment (those of the styles-box).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有使用过 CKEditor,但是,我看到你的问题并想“弄清楚这会很有趣。”好吧,这就是我的想法:(
是的,我发现了糟糕的文档,但是,这不是重点……不过,我会给他们评论代码的道具。)
这是一个 Javascript 函数来帮助您的点击事件:
现在,您可以创建一个像这样的链接:
并使用一些 jQuery 来增加它的趣味性:
我对按钮图标部分不是 100% 确定。我没有图标可以尝试。但是,根据一些帖子,它应该可以正常工作。无论如何,jQuery 单击绑定有效。
应该差不多就是这样了!我必须进行大量的挖掘才能弄清楚这一点,但看到它起作用确实令人满意!
I haven't used CKEditor, but, I saw your question and thought "That would be fun to figure out." Well, here is what I figured out:
(yes, I found terrible documentation, but, that's not the point...I will give them props for commenting their code, though.)
Here is a Javascript function to aid your click events:
Now, you can create a link like this:
and use a bit of jQuery to spice it up:
I am not 100% sure about the button icon part. I didn't have an icon to try it with. But, according to a few posts, it should work fine. Regardless, the jQuery click binding works.
That should be pretty much it! I had to do quite a bit of digging around to figure this out, but it certainly is satisfying to see it work!
这里有一个选项:
首先,您可以设置想要在 CSS 类中尝试的所需样式。然后,您可以在单击该按钮时设置测试 div 的 className。这是一个简单的示例:
test.css:
test.html
Here's one option
First, you can setup the desired styles you want to try out in a CSS class. Then, you can set the className for the test div when you click that button. Here's a simple example:
test.css:
test.html