简体   繁体   English

使用JavaScript从html文档中的链接获取值并将它们存储在数组中

[英]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.

相关问题 从列中获取所有值,并将它们放入javascript中的数组 - Get all values from column and put them into an array in javascript HTML Javascript | 如何获取链接数组的值 - HTML Javascript | how to get a value of a links array 如何<span>从数组中</span>提取<span>元素值并将其存储到另一个数组中</span> - how to extract <span> element values from an array and store them into another array.Javascript 从HTML的textarea获取输入数据,并将该值存储在数组中 - Get the input data from textarea of HTML and store that values in an array javascript全局变量不能存储值(如果它暗示从HTML元素中提取值)? - javascript global variables can't store values if it implies extracting them from HTML elements? 如何从服务器端JavaScript获取值并将其存储在Swift的plist中? - How to get values from server side JavaScript and store them in a plist in Swift? 将下拉值传递给javascript函数并将它们存储为数组 - Pass dropdown values to javascript function and store them as array 如何获取和替换多个跨度元素的值(来自标记字符串)并将它们存储在数组中 - How to get and replace values of multiple span elements (from a string of markup) and store them in an array 我如何从表的每一行获取值并将其存储在js数组中 - How do i get the values from each row of a table and store them in a js array 是否有可能使用javascript从HTML文档中获取包含“纯”文本值的所有HTML内容元素? - Is there any possibility to get all HTML content elements that contains “plain” text values from HTML document using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM