使用内置DOM方法或原型从HTML字符串创建新的DOM元素

走远了吗. 提交于 2020-07-26 11:38:36

问题:

I have an HTML string representing an element: '<li>text</li>' . 我有一个表示元素的HTML字符串: '<li>text</li>' I'd like to append it to an element in the DOM (a ul in my case). 我想将其附加到DOM中的元素(以我的情况为ul )。 How can I do this with Prototype or with DOM methods? 如何使用Prototype或DOM方法做到这一点?

(I know i could do this easily in jQuery, but unfortunately we're not using jQuery.) (我知道我可以在jQuery中轻松完成此操作,但不幸的是,我们没有使用jQuery。)


解决方案:

参考一: https://stackoom.com/question/24Y3/使用内置DOM方法或原型从HTML字符串创建新的DOM元素
参考二: https://oldbug.net/q/24Y3/Creating-a-new-DOM-element-from-an-HTML-string-using-built-in-DOM-methods-or-Prototype
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!