Javascript 如何在jquery中从同一个类中获取值?
如何在jquery中从同一个类中获取值Javascript 如何在jquery中从同一个类中获取值?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,如何在jquery中从同一个类中获取值 <div class="wider-box google-map-wrapper"> <h3 class="touch-line uc">Product tags</h3> <div class="wider-box content-block profile-tags"> <p> <a href="/directory/product
<div class="wider-box google-map-wrapper">
<h3 class="touch-line uc">Product tags</h3>
<div class="wider-box content-block profile-tags">
<p>
<a href="/directory/product/electronic_goods/">Electronic Goods</a>
<a href="/directory/product/home_appliances/">Home Appliances</a>
</p>
</div>
<h3 class="touch-line uc">Brand tags </h3>
<div class="wider-box content-block profile-tags">
<p>
<a href="/directory/brand/apple/">Apple</a>
<a href="/directory/brand/breville/">Breville</a>
<a href="/directory/brand/de_longhi/">De Longhi</a>
<a href="/directory/brand/dyson/">Dyson</a>
<a href="/directory/brand/kenwood/">Kenwood</a>
</p>
</div>
及
两者的格式应该不同。尝试使用每个函数并获取
使用map():
删除join()以获取数组。您可以向anhour标记添加一些类,然后将其放在不同的对象中
menu1 for all menu 1s
<a class='menu1' href="/directory/product/electronic_goods/">Electronic Goods</a>
menu2 for all menu 2s
<a class='menu2' href="/directory/brand/apple/">Apple</a>
所有菜单1的菜单1
所有菜单2的菜单2
看小提琴
试试这样的方法
var all_list=[];
$('div.profile-tags').each(function(){
var text_list = []
$(this).find('a').each(function(){
text_list.push($(this).text());
})
all_list.push(text_list);
});
console.log(all_list[0].join('|'));
console.log(all_list[1].join('|'));
附加到@A.Wolff answer之后,如果您想分别提醒两个类锚文本,请使用以下内容:
$(document).ready(function() {
$( ".wider-box" ).each(function() {
var str = $(this).find("a").map(function(){
return $.trim(this.innerHTML)
}).get().join(' | ');
alert(str);
});
});
此处演示:您可以执行以下操作:
var data = [];
$('.wider-box p').each(function () {
data.push($(this).children().map(function () {
return $(this).text();
}).get());
});
这是一个演示:。你没有试过什么吗?请花点时间读一下:。我想他想要两个字符串。一个是“产品”,另一个是“品牌”。@FelipeFonseca没有看到,thx。所以只需为每个循环(映射)使用更具体的选择器。如果OP不是太懒,我想他应该能够修改代码
menu1 for all menu 1s
<a class='menu1' href="/directory/product/electronic_goods/">Electronic Goods</a>
menu2 for all menu 2s
<a class='menu2' href="/directory/brand/apple/">Apple</a>
var all_list=[];
$('div.profile-tags').each(function(){
var text_list = []
$(this).find('a').each(function(){
text_list.push($(this).text());
})
all_list.push(text_list);
});
console.log(all_list[0].join('|'));
console.log(all_list[1].join('|'));
$(document).ready(function() {
$( ".wider-box" ).each(function() {
var str = $(this).find("a").map(function(){
return $.trim(this.innerHTML)
}).get().join(' | ');
alert(str);
});
});
var data = [];
$('.wider-box p').each(function () {
data.push($(this).children().map(function () {
return $(this).text();
}).get());
});