[英]get values from links in html document with JavaScript and store them in an array
I have a table with links in the html document and they looks something like (first link is just javascript:): 我在html文档中有一个带有链接的表,它们看起来像(第一个链接只是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. 我要给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 ""). 我在数组中得到了想要的值,但第一位是“ j”(没有“”)。 I guess it is because of +2 after the indexOf but how do I get rid of the j?
我想这是因为indexOf之后是+2,但是如何摆脱j? I only want the numbers in the array.
我只想要数组中的数字。
Thanks in advance. 提前致谢。
Edit: or is there a better way to get the ID's? 编辑:还是有更好的方法来获取ID? edit2: the alert shows j,1,2,4,5,7,8,10 and so on
edit2:警报显示j,1,2、4、5、7、8、10等
var startIndex = link.indexOf(",'");
var endIndex = link.indexOf("');");
if ( startIndex >= 0 && endIndex >= 0 ) {
var linkID = link.substring( startIndex+2, endIndex );
hrefs.push(linkID);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.