简体   繁体   English

JavaFx:如何使HTMLEditor不创建模板HTML文档?

[英]JavaFx: how to make HTMLEditor not to create emtire HTML document?

When javafx create object of HTMLEditor it has the empty html document with the following html: 当javafx创建HTMLEditor的对象时,它具有带有以下html的空html文档:

<html dir="ltr"><head></head><body contenteditable="true"></body></html>

However, I don't need entire html document. 但是,我不需要整个html文档。 I want to work only with some node in html editor, for example with div . 我只想使用html编辑器中的某些节点,例如div I tried to do 我试着做

htmlEditor.setHtmlText(null) or htmlEditor.setHtmlText("")

but it is ignored. 但它被忽略了。 When I did 当我做的时候

htmlEditor.setHtmlText("<div></div>")

I got: 我有:

<html dir="ltr"><head></head><body contenteditable="true"><div></div></body></html>

So, how to do it? 那么,该怎么做呢?

HtmlEditor always trying to have valid html structure, that is why it adds tags. HtmlEditor总是尝试具有有效的html结构,这就是为什么要添加标签的原因。

You need DOM manipulation library, for example jdom . 您需要DOM操作库,例如jdom Or manage DOM transition before sending to render, when applying string to editor. 或在将字符串应用于编辑器时,在发送渲染之前管理DOM过渡。

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

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