如何放置所有元素?使用 jQuery 数组中的内容?
<div id="main">
<p>Text1</p>
<p>Text2</p>
<p>Text3</p>
</di>
结果应该是:
["text1","text2","text3"]
<div id="main">
<p>Text1</p>
<p>Text2</p>
<p>Text3</p>
</di>
Result should be :
["text1","text2","text3"]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
jQuery 为此提供了
.map()
:。 map() 迭代其元素,对每个元素调用一个函数,并将函数的返回值记录在它返回的新数组中。
您也可以使用简单的
.each()
解决此问题:jQuery provides
.map()
for this:.map()
iterates over its elements, invoking a function on each of them and recording the return value of the function in a new array, which it returns.You could also have solved this with a simple
.each()
:这将起作用:
map() 允许您迭代每个匹配项并从中获取一个值,该值将插入到类似数组的对象中。 get() 然后将其作为 Javascript 数组返回,而 .join 将数组转换为字符串。
This will work:
map() lets you iterate over each match and get a value from it, which is inserted into an array-like object. get() then returns it as a Javascript array, and .join makes the array into a string.