我正在尝试为某个应用编程所见即所得。一切似乎都还好,除了没有[object HTMLBodyElement]我无法获得iframe的值

let content = this.richtextarea.nativeElement.contentDocument.body


当我console.log(content)时,我得到了<body>...</body>,但是尝试将其存储到数据库中时,它说它是[object HTMLBodyElement]

我尝试将iframe值转换为字符串,但没有运气。

如何获取iframe的值作为字符串?

有更好的方法吗,例如将Iframe的值移动到textarea,然后在组件类中获取textarea的值?

最佳答案

let content = this.richtextarea.nativeElement.contentDocument.body


给您元素而不是字符串html,您需要使用outerHTML

this.richtextarea.nativeElement.contentDocument.body.outerHT‌​ML

innerHTML

this.richtextarea.nativeElement.contentDocument.body.innerHT‌​ML

09-04 22:18
查看更多