有没有一种简单的方法可以在JavaScript中获取一串html并去除html? 最佳答案 如果您在浏览器中运行,那么最简单的方法就是到letthebrowserdoitforyou...functionstripHtml(html){lettmp=document.createElement("DIV");tmp.innerHTML=html;returntmp.textContent||tmp.innerText||"";}注意:正如人们在评论中指出的那样,如果您不控制HTML的源代码,最好避免这种情况(例如,不要在任何可能来自
这个问题在这里已经有了答案:关闭10年前.PossibleDuplicate:Whenusinglxml,cantheXMLberenderedwithoutnamespaceattributes?如何从lxml.objectify.ObjectifiedElement中去除python属性?示例:In[1]:fromlxmlimportetree,objectifyIn[2]:foo=objectify.Element("foo")In[3]:foo.bar="hi"In[4]:foo.baz=1In[5]:foo.fritz=NoneIn[6]:printetree.tostrin
这个问题在这里已经有了答案:关闭10年前.PossibleDuplicate:Whenusinglxml,cantheXMLberenderedwithoutnamespaceattributes?如何从lxml.objectify.ObjectifiedElement中去除python属性?示例:In[1]:fromlxmlimportetree,objectifyIn[2]:foo=objectify.Element("foo")In[3]:foo.bar="hi"In[4]:foo.baz=1In[5]:foo.fritz=NoneIn[6]:printetree.tostrin