ExtJS:向 htmleditor 添加按钮
我正在使用 ExtJS,并且我的表单中有一个 htmleditor。我想向该元素添加一个自定义按钮(例如在所有其他按钮(如对齐、字体粗细等)之后)。这个按钮基本上应该在 htmlfield 中插入一个标准模板。作为这个模板 html,按钮的行为应该像这样
- 切换到 HTML 模式(就像按下“源”按钮时)
- 插入一些内容
- 切换回所见即所得模式(就像再次按下“源”按钮时)
感谢您的关注
I am using ExtJS and I have a htmleditor in my form. I would like to add a custom button to that element (for example after all other buttons like alignments, font weights, ...). This button should basically insert a standard template in the htmlfield. Being this template html, the behaviour of the button should be like this
- Switch to HTML mode (like when pressing Source button)
- Insert something
- Switch back to WYSIWYG mode (like when pressing the Source button again)
Thanks for your attention
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无需切换到 HTML 模式。只需将
insertAtCursor
函数与 HTML 模板结合使用即可。我制作了这个简单的示例,说明如何添加插入水平标尺的按钮(
标记):您可以看到它在以下位置运行:jsfiddle.net/protron/DCGRg/183/
但我真的建议您查看 HtmlEditor.Plugins (或ateodorescu/mzExt 用于 ExtJS 4)。在那里您可以找到更多有关添加自定义按钮的信息,例如,如何在选择某些内容时启用/禁用按钮、放置分隔符等。
You don't need to switch to HTML mode. Just use the
insertAtCursor
function with the HTML template.I made this easy example of how to add button which inserts a horizontal ruler (
<hr>
tag):You can see it running at: jsfiddle.net/protron/DCGRg/183/
But I really recommend you to check out HtmlEditor.Plugins (or ateodorescu/mzExt for ExtJS 4). There you can find a lot more about adding custom buttons, for instance, how to enable/disable the buttons when something is selected, put separators, etc.
您还可以使用 ExtJS.ux.HtmlEditor.Plugins : https://github.com/ VinylFox/ExtJS.ux.HtmlEditor.Plugins
You also can use ExtJS.ux.HtmlEditor.Plugins : https://github.com/VinylFox/ExtJS.ux.HtmlEditor.Plugins
除了上面的@proton很好的答案之外,还有另一种方法可以插入按钮到工具栏,与将它们添加到末尾不同。
在我的回答中,我将其编写为名为“RichTextBox”的新控件(而不是插件),但这可以通过任何其他方式完成:
In addition to @proton great answer above, there's another way to insert buttons to the toolbar, different from adding them to the end.
In my answer i'll write it as a new control named 'RichTextBox' (and not as a plugin) but this can be done in any other way: