javascript - jQuery .html() 没有选择一些电子邮件?

标签 javascript jquery

您好,我开始使用 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/

相关文章:

javascript - 使用 touchstart 还是 mousedown?

javascript - 将 JavaScript 字符串转换为数组

javascript - 如何检测鼠标是否位于 jQuery 或 Javascript 中的项目上

jquery - .jquery 中的每个循环查找指向特定位置的所有 anchor 并更改类

javascript - Div insideHTML 重写失败

javascript - 从 MEAN 堆栈应用程序的 Controller 中的范围变量中选择不同的值

javascript - 使用 jQuery 隐藏元素;我应该使用哪种方法,为什么?

javascript - 从数据库 mysql php 删除引导警报

jquery - 使用 jQuery 从标签中获取文本

javascript - Chart.js 饼图动画,当通过垂直滚动在页面中的某个位置时播放一次