简体   繁体   English

如何从jquery children方法获取字符串?

[英]How to get string from jquery children method?

$item
<div><p>adfadf</p><p>adfadf</p></div>

$item.children()
[<p>​adfadf​</p>​, <p>​adfadf​</p>​]

$item.children().toString()
"[object Object]"

$item.children().text()
"adfadfadfadf"

$item.children().prop('outerHTML')
"<p>adfadf</p>"

i want the output to be "<p>​adfadf​</p>​<p>​adfadf​</p>" . 我希望输出为"<p>​adfadf​</p>​<p>​adfadf​</p>" "outerHTML" is working but it is returning only one node data in string how to get all the children data in string ? “ outerHTML”正在工作,但它仅返回字符串中的一个节点数据,如何获取字符串中的所有子数据?

why not simply 为什么不简单

$item.html();

or 要么

var html = "";
$item.children().each( function(){

  html += $( this ).prop('outerHTML');

} );
console.log( html );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM