I have a table with links in the html docum开发者_运维百科ent and they looks something like (first link is just javascript:):
javascript:
javascript:SelectField('{a guid}','2');return false;
javascript:SelectField('{a guid}','23');return false;
javascript:SelectField('{a guid}','1');return false;
javascript:SelectField('{a guid}','14');return false;
I want the number after the guid.
My current code is:
$("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 linkID = link.substring( link.indexOf(",'")+2, link.indexOf("');") )
hrefs.push(linkID);
alert(hrefs);
});
I get the values I want in an array but the first place is "j" (without ""). I guess it is because of +2 after the indexOf but how do I get rid of the j? I only want the numbers in the array.
Thanks in advance.
Edit: or is there a better way to get the ID's? edit2: the alert shows j,1,2,4,5,7,8,10 and so on
var startIndex = link.indexOf(",'");
var endIndex = link.indexOf("');");
if ( startIndex >= 0 && endIndex >= 0 ) {
var linkID = link.substring( startIndex+2, endIndex );
hrefs.push(linkID);
}
精彩评论