我有这样的设计:
HTML 欢迎页面
<div id="links">
<a class="view" href="www.this.com/43534534534"><span class="link_number"></span>This one for all</a>
<a class="view" href="www.this.com/99540594544"><span class="link_number"></span>This not but why not</a>
....这里有 100 个......
</div>
JQUERY
$('#links').find('a.view').each(function(){
quickC = $(this).attr('href');
$.get(quickC, function(html){
var quantity = $(html).find('a.my_text').size();
$('.link_number').append(quantity);
});
});
HTML 页面 #1 www.this.com/43534534534
<a class="my_text">this this</a>
<a class="my_text">this this this this</a>
<a class="my_text">this this this</a>
HTML 页面 #2 www.this.com/99540594544
<a class="my_text">this this</a>
<a class="my_text">this this this this</a>
...
JQUERY 的结果
第 1 页 = 找到 3 个链接
Page #2 = 找到 2 个链接
...
期望的结果
HTML 欢迎页面
<div id="links">
<a class="view" href="www.this.com/43534534534"><span class="link_number">**3**</span>This one for all</a>
<a class="view" href="www.this.com/99540594544"><span class="link_number">**2**</span>This not but why not</a>
....这里有 100 个......
问题/问题:
一切正常,除了我不知道为什么它只拉第一个链接并将相同的数字传播到其他 link_number 类。
问题,如何使这段代码工作,因为我可能有 100 个具有特定 href 的链接,并将处理后的链接号返回到欢迎页面上的相关 a.view 链接?
感谢您的意见!谢谢。
最佳答案
$('.link_number').append(quantity);
将找到所有跨度,而不仅仅是您正在下载的事件链接中的跨度。所以你必须将实际的链接对象传递给设置链接数的函数,这样它只能找到一个跨度:
$.get(quickC,{},{linkobj: $(this)}).success(function(html) {
var quantity = $(html).find('a.my_text').size();
$('.link_number', this.success.linkobj).append(quantity);
});
问候
关于javascript - Jquery 查找具有相同类的多个链接 href 并根据获取页面更改每个链接的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25534606/