我有一组我想在页面上找到的链接,但只有当 href 包含单词“PlaySounds”时,我尝试了以下代码,但我没有定义。
http://www.website.com/uno/PlaySounds.aspx?Id=546444456
http://www.website.com/uno/PlaySounds.aspx?Id=347457458
http://www.website.com/uno/PlaySounds.aspx?Id=275656573
http://www.website.com/uno/PlaySounds.aspx?Id=976645654
hrefs = Array.prototype.filter.call(document.getElementsByTagName("a"), function(node) {
return node.href.indexOf("PlaySounds") === 0;
}).map(function(node) {
return node.href;
});
randomHref = hrefs[Math.floor(Math.random() * hrefs.length)];
console.log(randomHref );