简体   繁体   English

如何从Dijit编辑器中获取整个HTML值

[英]How to get the whole HTML value from Dijit Editor

Hello Experts I need help 您好专家,我需要帮助

I'm using dojo Dijit Editor "rich text editor" field in my widget, on page load I fetch HTML text from database and I set the rich text editor with the HTML normally, Then user can edit the displayed text and on page close I have to set the field in database with the source HTML of the edited text by user the problem is when I do the following " myDB_txt=myEditor.getValue() ;" 我在窗口小部件中使用dojo Dijit Editor “ RTF文本编辑器”字段,在页面加载时,我从数据库中获取HTML文本,并以HTML正常设置RTF编辑器,然后用户可以编辑显示的文本并在页面关闭时我必须由用户设置数据库中带有已编辑文本的源HTML的字段,问题是当我执行以下“ myDB_txt=myEditor.getValue() ;”时 getValue() doesn't return the complete HTML code it removes HTML tag and header tag and body tag which causes me troubles. getValue()不返回完整的HTML代码,而是删除了HTML标记,标头标记和正文标记,这给我带来了麻烦。

You could try the following to retrieve the value from your dijit/Editor instance. 您可以尝试以下操作从dijit/Editor实例中检索值。

var content = myEditor.attr("value");
var openTags = '<html><head></head><body>';
var closeTags = '</body></html>';
var html = openTags + content + closeTags; // use this

or 要么

var htmlWrapper = function(content){
    return '<html><head></head><body>' + content + '</body></html>';
}; 
var html = htmlWrapper(myEditor.attr("value"));

Simply use myEditorWidget.get("Value") where myEditorWidget refer to your dijit/Editor indtance 只需使用myEditorWidget.get("Value") ,其中myEditorWidget引用您的dijit/Editor实例

To wrap this result you can define a function that return result wraped by html tags 要包装此结果,您可以定义一个返回由html标签包装的结果的函数

wrapResult(myEditor.get("value")));

function wrapResult(html) {

  return "<html> <head></head> <body>"+html+"</body></html>";

}

Here is a Sample with wraped result Fiddle . 这是带有包装结果Fiddle的Sample。

Otherwise If you want to get the whole HTML enclosing the content dijit , 否则,如果您想获取包含内容dijit的整个HTML,

you will get access to it's Iframe ( that has the id="editor_iframe" ) and then get get the html document of this last like bellow (here you should import dojo/query package) 您将可以访问它的Iframe (具有id="editor_iframe" ),然后获取像波纹管这样的最后一个的html document (此处应导入dojo/query包)

query("#editor_iframe")[0].contentDocument.documentElement.outerHTML

Here is another Fiddle . 这是另一个小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM