String 如何将html对象转换为字符串类型?

String 如何将html对象转换为字符串类型?,string,html-parsing,String,Html Parsing,我使用jQuery方法获取某种类型的html对象: var content = $('#cke_ckeditor iframe').contents().find('.cke_show_borders').clone(); 然后我想将其转换为string类型: console.log(content[0].toString()); 但结果是: [object HTMLBodyElement] 我怎样才能把它变成真正的字符串 顺便问一下,我可以将转换后的html字符串转换为html对象吗?您

我使用jQuery方法获取某种类型的html对象:

var content = $('#cke_ckeditor iframe').contents().find('.cke_show_borders').clone();
然后我想将其转换为
string
类型:

console.log(content[0].toString());
但结果是:

[object HTMLBodyElement]
我怎样才能把它变成真正的字符串


顺便问一下,我可以将转换后的html字符串转换为html对象吗?

您可以尝试以下操作:

content.text();
我相信您希望使用:


console.log(content.outerHTML)
您可以使用此
content[0].prop('outerHTML')

它对我有用


参考资料:

我也有同样的问题


var docString=“”+content.documentElement.innerHTML+”

将jQuery对象转换为字符串的正确方法:

var content=$('#cke_ckeditor').find('.cke_show_borders').eq(0.clone()


log(content.get(0.outerHTML)

“outerHTML”为我工作

在Google标记管理器中的“CustomJavasctipt”部分{{Click Element}}返回[object HtmleElement]

function() {
   var elm = {{Click Element}};
   return elm.outerHTML; // working
}
结果-

<i _ngcontent-c1="" class="material-icons">edit</i>
编辑

这向我证明了它是有效的。console.log(JSON.stringify(content[0].outerHTML))这起作用了-我在尝试使用
.toString()
JSON.stringify
时遇到了麻烦