如何在JavaScript中获取<a href="http://www.mysite.com">的URL?

我正在处理JavaScript中的一些文本(使用节点,所以请不要jQuery)。 我想提取页面上<a>标签中的所有URL。 我怎样才能在JavaScript中做到这一点?

 var myArray = preg_match_all("<a.*?href=[\'|\"](.*?)[\'|\"]", "How can I get the URL of an <a href=\"http://www.mysite.com\"> in JavaScript? How can I get the URL of an <a href=\"http://www.mysite.org\"> in JavaScript?") if ( myArray != null) { for ( i = 0; i < myArray.length; i++ ) { alert(myArray[i]); } } function preg_match_all(regex, haystack) { var globalRegex = new RegExp(regex, 'g'); var globalMatch = haystack.match(globalRegex); matchArray = new Array(); for (var i in globalMatch) { nonGlobalRegex = new RegExp(regex); nonGlobalMatch = globalMatch[i].match(nonGlobalRegex); matchArray.push(nonGlobalMatch[1]); } return matchArray; } 

preg_match_all函数取自http://coding.pressbin.com/16/Javascript-equivalent-of-PHPs-pregmatchall

我build议使用在线testing器,例如: http : //www.pagecolumn.com/tool/regtest.htm