[英]Can I get the raw HTML output from a JS HTML object?
I've created multiple HTML objects using我使用创建了多个 HTML 对象
document.createElement("");
after that, I applied some modifiers like CSS, class names and onclick behaviors.之后,我应用了一些修饰符,例如 CSS、类名和点击行为。 How can I get the raw HTML code that is generated?如何获取生成的原始 HTML 代码? My solution is creating an invisible div, adding the element as a child and call我的解决方案是创建一个不可见的 div,将元素添加为子元素并调用
document.getElementBy("my-invisible-div").innerHTML
to get the HTML.获取 HTML。 Is there a better way of doing this?有没有更好的方法来做到这一点? I need it for a database export and I don't want to have my HTML code in a string with placeholders.我需要它来导出数据库,并且我不想将我的 HTML 代码放在带有占位符的字符串中。
Thanks for any advice感谢您的任何建议
Does something like this work for you:这样的事情对你有用吗:
var element = document.createElement("div")
console.log(element.outerHTML)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.