如何使用javascript/jquery和php从媒体编辑器保存数据
我正在开发一个博客,我想添加媒体编辑器,以获取我的内容并保存。我一直在网上搜索,我自己也尝试过使用JavaScript,但它没有给我任何东西 HTML如何使用javascript/jquery和php从媒体编辑器保存数据,jquery,Jquery,我正在开发一个博客,我想添加媒体编辑器,以获取我的内容并保存。我一直在网上搜索,我自己也尝试过使用JavaScript,但它没有给我任何东西 HTML 让我们假设您以与上面示例中相同的方式实例化了编辑器: var editor = new MediumEditor('.editable', { ... }); 如果您只是想获取编辑器的内容,那么只需使用editor.getContent()helper方法(文档)即可返回编辑器的html内容。这将为您提供编辑器元素的.innerHTML var
让我们假设您以与上面示例中相同的方式实例化了编辑器:
var editor = new MediumEditor('.editable', { ... });
如果您只是想获取编辑器的内容,那么只需使用editor.getContent()
helper方法(文档)即可返回编辑器的html内容。这将为您提供编辑器元素的.innerHTML
var x = editor.getContent(); // x is the innerHTML of the editor
如果您希望收到编辑器更改的通知(键入、粘贴、格式更改等),您可以订阅editableInput
自定义事件,并在发生这些更改时收到通知:
editor.subscribe('editableInput', function (eventObj, editable) {
// You can get the content of the editor at this point multiple ways
var x = editable.innerHTML; // editable is the editor <div> element that was changed
var y = editor.getContent(); // getContent() returns the content of the editor as well
x === y; // TRUE
});
我不确定一旦您访问了内容,您希望如何处理这些内容,但希望上面的示例能够帮助您整合所需的功能。我非常感谢您的代码@Jason,这很有帮助,您也给了我额外的提示,但我以前确实尝试过,它确实为我抓住了整个
innerHTML
:
$("#publish_article").click(function() {
editor.html()
});
editor.subscribe('editableInput', function (eventObj, editable) {
// You can get the content of the editor at this point multiple ways
var x = editable.innerHTML; // editable is the editor <div> element that was changed
var y = editor.getContent(); // getContent() returns the content of the editor as well
x === y; // TRUE
});
$('#publish_article').click(function () {
var x = editor.getContent();
// The publish button has been clicked and you now have the content of the editor in x
});
$("#publish_article").click(function() {
editor.html()
});