简体   繁体   English

通过外部HTML设置Quill.js的内容

[英]Set the Content of Quill.js by external HTML

I try to set the content of quill.js with external html like this: 我尝试使用如下外部html设置quill.js的内容:

quill.container.querySelector('.ql-editor').innerHTML = myHtml;

But not all of the myHtml code is shown in the editor! 但是,并非所有myHtml代码都显示在编辑器中!

When I do this: 当我这样做时:

document.getElementById("editor").innerHTML = myHtml; 

The whole html is there but the edit functionality is not given (because inside of #editor there is .ql-editor which is overriden. 整个html都存在,但是没有提供编辑功能(因为#editor内部存在.ql-editor,它会被覆盖。

See here: https://fiddle.jshell.net/ppkxL2pd/16/ 看到这里: https : //fiddle.jshell.net/ppkxL2pd/16/

Feel free to change the two given possiblities to understand what I mean. 随意更改两个给定的可能性以了解我的意思。

Why myHtml is not shown correctly? 为什么myHtml无法正确显示?

The problem was with the way you were assigning html to myHtml variable. 问题在于您将html分配给myHtml变量的方式。

You rightly used backtick as template literal but it doesn't seem to work in this particular case. 您正确地将反引号用作模板文字,但在这种情况下似乎不起作用。

Solutions : 解决方案:

  1. Keep entire html on single line. 将整个html放在一行上。 (Bad way). (坏方法)。 Working Demo here 在这里工作演示
  2. Use \\ at the end of every line. 在每行末尾使用\\ Working Demo here 在这里工作演示

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

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