您好,我开始使用 jQuery,当我尝试选择 div 内的内容时,某些电子邮件没有被选择?我正在使用 Safari 的控制台来执行 jQuery 代码。我使用 .text()
得到了所需的结果,但为什么 .html()
不起作用?
jQuery
$("input[type=checkbox]:checked").parents('.organizer_listing').find('.organizer_listing_contact_email')
结果
[
<div class="organizer_listing_contact_email">ciara@bhre.net</div>
,
<div class="organizer_listing_contact_email">hihi-p38sn-2788580457@somewhere.org</div>
,
<div class="organizer_listing_contact_email">hihi-2xxtn-2783323299@someowhere.org</div>
]
jQuery
$("input[type=checkbox]:checked").parents('.organizer_listing').find('.organizer_listing_contact_email').html()
结果
"ciara@bhre.net"
最佳答案
访问器方法(其中大多数也可以是修改器,但无论如何)仅适用于结果集中的第一项。
也就是说,.html()
将为您提供集合中第一项的 html,就像 .attr('href')
将为您提供第一项的 href
属性。
相反,您可能想使用 .map
...find('.organizer_listing_contact_email').map(function () {
return $(this).html();
}).get();
关于javascript - jQuery .html() 没有选择一些电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8887564/