在 jQuery 上获取 href 属性 [英] Get href attribute on jQuery
本文介绍了在 jQuery 上获取 href 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些表格行
<td><div class="cpt"><h2><a href="/ref/ref/1.html">示例</a></td></tr><!--更多元素--><tr class="b_row"><td><div class="cpt"><h2><a href="/ref/two/23.html">示例 N</a>
</td></tr>
我需要在属性中获取超链接.我用这个脚本
函数 openAll(){$("tr.b_row").each(function(){var a_href = $('div.cpt').find('h2 a').attr('href');alert("Href 是:" + a_href);}
问题:变量a_href
总是/ref/ref/1.html
解决方案 在循环中你应该引用当前被处理的元素,所以写:
var a_href = $(this).find('div.cpt h2 a').attr('href');
I have some table rows
<tr class="b_row">
<td>
<div class="cpt">
<h2>
<a href="/ref/ref/1.html">example</a>
</h2>
</div>
</td>
</tr>
<!--more elements -->
<tr class="b_row">
<td>
<div class="cpt">
<h2>
<a href="/ref/two/23.html">example N</a>
</h2>
</div>
</td>
</tr>
I need to get hyperlinks in attribute. I use this script
function openAll()
{
$("tr.b_row").each(function(){
var a_href = $('div.cpt').find('h2 a').attr('href');
alert ("Href is: " + a_href);
}
Problem: variable a_href
is always / ref/ref/1.html
解决方案 In loop you should refer to the current procceded element, so write:
var a_href = $(this).find('div.cpt h2 a').attr('href');
这篇关于在 jQuery 上获取 href 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
登录
关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆