[我想用纯JavaScript编写一个函数,该函数将类Jquery选择器与:eq(0)声明一起使用,例如遍历像这样的表
$('tr:eq(8) > td:eq(13)').val();
为此,我试图编写一个正则表达式,但我停留在这里
var str = "I don't want +5+ and not 10 or [12] nor (120) but :eq(5) and :eq(120)";
var matches = str.match(/\:eq\(\d+(\d{1,2})\)?/g);
console.log('matches: '+matches);
仅返回matches: :eq(120)
,而不返回所需的matches: :eq(5),:eq(120)
。我在这里可以做什么?
您可以简化您的正则表达式:
var matches = str.match(/\:eq\(\d+\)/g);