最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get link value in html document with jQuery? - Stack Overflow

programmeradmin4浏览0评论

Let's say I have a link in a table like:

    <td class="ms-vb" width="100%">
<a onfocus="OnLink(this)" href="/Lists/Business%20Divisions/DispForm.aspx?ID=2" onclick="GoToLink(this);return false;" target="_self">Train<img src="/_layouts/images/blank.gif" class="ms-hidden" alt="" width="1" border="0" height="1">
</a></td>

How can I get the value Train with jQuery?

Thanks in advance.

edit: I currently get the querystring value from every link and push them into an array with the following code:

$("table").each(function(index, value) {
    $(this).addClass("table" + index);
});


var hrefs = new Array();
$('.table449').children().children().each(function(){
var link = ($(this).find('a').attr('href'));
var startIndex = link.indexOf(",'");
var endIndex = link.indexOf("');");
if ( startIndex >= 0 && endIndex >= 0 ) {
    var linkID = link.substring( startIndex+2, endIndex );
  hrefs.push(linkID);
}
alert(hrefs);
});

What I want to do is to store the values like Train in another array.

Let's say I have a link in a table like:

    <td class="ms-vb" width="100%">
<a onfocus="OnLink(this)" href="/Lists/Business%20Divisions/DispForm.aspx?ID=2" onclick="GoToLink(this);return false;" target="_self">Train<img src="/_layouts/images/blank.gif" class="ms-hidden" alt="" width="1" border="0" height="1">
</a></td>

How can I get the value Train with jQuery?

Thanks in advance.

edit: I currently get the querystring value from every link and push them into an array with the following code:

$("table").each(function(index, value) {
    $(this).addClass("table" + index);
});


var hrefs = new Array();
$('.table449').children().children().each(function(){
var link = ($(this).find('a').attr('href'));
var startIndex = link.indexOf(",'");
var endIndex = link.indexOf("');");
if ( startIndex >= 0 && endIndex >= 0 ) {
    var linkID = link.substring( startIndex+2, endIndex );
  hrefs.push(linkID);
}
alert(hrefs);
});

What I want to do is to store the values like Train in another array.

Share Improve this question edited Aug 12, 2010 at 1:07 Peter asked Aug 12, 2010 at 0:58 PeterPeter 6852 gold badges13 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Hard to tell with such a small snippet. In the provided snippet either of these would work:

$("td a").text();

$(".ms-vb a").text();
发布评论

评论列表(0)

  1. 暂无评论