- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望用户能够使用转义键以内联模式中止 tinyMCE 编辑器中的任何更改。这是 HTML:
<div id="tinymce">
<p>Foo Foo Foo</p>
</div>
和脚本:
tinymce.init({
selector: '#tinymce',
inline: true,
setup: function (editor) {
editor.on('keydown', ((e) => {
var tinyMceEditor = tinyMCE.get(e.target.id);
if (e.keyCode === 27) { // escape
// This will hide the editor but it won't come back when trying to re-edit
tinyMceEditor.hide();
}
}));
}
});
它也是一个 jsfiddle:http://jsfiddle.net/kfnyqufm/
点击 escape 会像我想要的那样关闭编辑器,但有两个问题:(1) 单击文本时编辑器不返回 (2) 任何编辑的文本都不会恢复为原始值
最佳答案
(1)点击文本编辑器不返回
发生这种情况是因为当按下 esc 时您完全隐藏了编辑器,并且不再显示它。你有(至少)两个选项来解决这个问题:
#tinymce
div 再次获得焦点时显示编辑器;或#tinymce
上的 blur()
方法(这将自动隐藏编辑器,它会来再次点击返回)如果你选择第二个选项(我认为它会更简单),代码将是这样的(只有与退出按钮相关的部分):
if (e.keyCode === 27) { // escape
document.getElementById("tinymce").blur();
}
你也可以在this version of your JSFiddle上看到它.
(2) 任何编辑过的文本都不会恢复到原始值
这有点棘手(但仍然很简单),因为您需要跟踪旧值并在按下 esc 时恢复。这样做的逻辑是:
#tinymce
div 获得焦点时:将内部 HTML 保存到 JavaScript 变量中(或在 localStorage
或 sessionStorage
中)。#tinymce
的内部HTML。存储旧值的代码是这样的:
// define a variable to store the old value
var old_value = "";
// save the old value when #tinymce gets focus
document.getElementById("tinymce").addEventListener("focus", function() {
old_value = document.getElementById("tinymce").innerHTML;
}, false);
然后您还需要在按下 esc 时恢复旧值:
if (e.keyCode === 27) { // escape
// blur the tinymce div and restore the old value
document.getElementById("tinymce").blur();
document.getElementById("tinymce").innerHTML = old_value;
}
您可以看到它在 this version of your JSFiddle 上完全正常工作.
关于javascript - 使用转义键取消内联 tinyMCE 编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34097706/
因为没有更多的 Tinymce 论坛,如果我可以问有没有办法通过在源代码中添加 style="width: or height:"来关闭表格功能。 谢谢 最佳答案 我通过将以下内容添加到 tinymc
我的页面加载了 5 个 div,可以使用 Tinymce 内联编辑器进行编辑。通过单击一个按钮(如此动态),我可以安心地使用 Jquery 加载 5 个新的。但是当然新的不会受到 Tinymce 的影
我想以相同的形式使用 2 个不同的 textareas 和 tinyMCE。第一个效果很好,但是每当我添加第二个时,第二个都会被禁用(当我从右下角手动放大时它会启用)。它们的字段名称和 id 是不同的
我不确定我是否理解正确,但我相信有一个免费的“基本”版本,如果您需要一些高级插件和技术支持,您只需付费。 情况真的是这样吗? 最佳答案 是 . 请查看 this link和 this link想要查询
我的一位用户对tinyMCE 中的撤消功能感到非常沮丧。它不是撤消最后一个微小的更改,而是撤消许多更改。这是每隔几秒拍摄一次快照的计时问题吗?这是可配置的吗? 其他信息:用户正在将信息从 Word 复
我有最新版本的 TinyMCE 编辑器,当我像那样传递图像链接时 http://www.w3schools.com/css/trolltunga.jpg它会自动转换为 .我试图捕获 paste_pr
如果编辑器当前内容的长度加上要粘贴的单词的长度超过指定的限制,我需要阻止tinyMCE的粘贴事件。我该怎么做?谢谢。 最佳答案 我错了。我不需要阻止或禁用 tinyMCE 中的粘贴来执行此操作。我使用
我正在使用 TinyMCE 插件并将 valid_elements 选项设置为: "a[href|target:_blank],strong/b,em/i,br,p,ul,ol,li" 即使没有列出数
我似乎无法在互联网上找到有关此的任何信息,但是 TinyMCE 4 中的图标如何工作? 我知道我可以按名称为按钮指定图标并为我的自定义按钮指定自定义图标,但是如果我想采用标准图标之一,在图像编辑应用程
每次我向 tinyMCE 添加图像时,它都会将图像 URL 转换为愚蠢的内容(删除主机名并添加 ../或任何它需要的内容),因此我将无法在任何其他级别使用 tinymce 创建的图像地点 ! 这可以以
我有一个包含多个文本区域的页面,可以用 TinyMCE 替换。 一些 Textareas 采用阿拉伯语文本,一些英语文本。 textareas 根据他们应该接收的输入正确设置了 dir -属性。 如何
我正在使用最新的 TinyMCE,它很棒,但我遇到的唯一问题是人们发布代码示例时。他们以 PRE 格式发布还是正常发布都没有关系。 TinyMCE 去掉了所有的缩进(Tabs)并使其难以阅读,这里有没
我一直在寻找几个小时来找到一个可以在图像中添加诸如“填充:5px”之类的东西的插件。每个人都通过纯 html 做到这一点吗?我们的客户需要一种方法来简单地使用按钮或右键单击上下文菜单来添加它。有什么建
我想要 tinymce 工具栏中的按钮。单击该按钮后,无论光标在哪里,“HELLO”都应出现在编辑器中。 版本:3.3.7 但我无法添加该按钮。 我试过添加这样的按钮 setup: function
我刚开始使用 TinyMCE 作为 WYSIWYG 编辑器,我想知道是否有人看到我的问题使用过这个不错的编辑器可以帮助我,这是我的脚本: tinyMCE.init({ mode :
我正在尝试从 ltr 设置 TinyMCE(版本 4.0.12)中的默认内容方向至 rtl . 我正在使用 directionality配置: directionality: 'rtl', ...但编
如何为粗体、下划线和删除线等基本内容覆盖 TinyMCE 的默认格式?目前生成的 HTML 使用样式化的跨度,这通常很好。不幸的是,在这种情况下,我需要做一些简单的解析并且需要元素是旧样式的 、 和
如何在 TinyMCE 中设置默认字体大小和背景颜色? 谢谢, 伊甸园 最佳答案 您也可以使用 Javascript 更改 css。 将此添加到您的 init 函数中: oninit : "postI
当我使用 TinyMCE 添加新表格时,表格几乎不可见,因为初始宽度只有几个像素。 有什么办法可以改变这种情况吗? 最佳答案 打开 table.js,转到第 30 行有内容 width = formO
我正在 TinyMCE 工具栏上制作一个额外的按钮(它用于 Wordpress,但我认为这并不重要)。 按下按钮并显示一个表单,我在配置它时完全不知所措,以便在表单上输入的值实际上传输到tinyMce
我是一名优秀的程序员,十分优秀!