如何转换Javascript Var持有Html到字符串?

时间:2015-12-03 20:45:30

标签: javascript html angularjs

        var originalHtmlString = '<p>Some text</p>'

        //Create an html object called myHtml that I can work with like w/ document
        var myHtml = document.createElement( 'html' );

        //Make the html object hold the html I wrote in a string so I can edit it as html
        myHtml.innerHTML = originalHtmlString;

        var stringifiedHtml = ???

如何打开&#34; myHtml&#34;使用后var变回一个字符串?

1 个答案:

答案 0 :(得分:3)

应该像

一样简单
var stringifiedHtml = myHtml.outerHTML;

Element.outerHTML