url解析javascript

url解析javascript,javascript,dom,Javascript,Dom,在amp之后的字符作为行尾,它将终止对该点的搜索。有人能告诉我一个不使用DOM解析器就能提供所需href的解决方案吗?你试过正则表达式吗?我不知道你所说的“搜索机制”是什么意思 例如: ; 另请参见尝试正则表达式 var htmlString = 'td3...(etc)'; var regex = /href="([^"])"/; var hrefUrl = regex.exec()[1]; console.log(hrefUrl); //?action=add&question=1

amp
之后的字符作为行尾,它将终止对该点的搜索。有人能告诉我一个不使用DOM解析器就能提供所需href的解决方案吗?你试过正则表达式吗?我不知道你所说的“搜索机制”是什么意思

例如:

;
另请参见尝试正则表达式

var htmlString = 'td3...(etc)';
var regex = /href="([^"])"/;
var hrefUrl = regex.exec()[1];
console.log(hrefUrl); //?action=add&question=149&cat=88 
var a='';
a、 匹配(/href=“(.*)/)[1];
这个怎么样:

创建临时div,设置innerHtml并进行解析

var a='<a href="?action=add&question=149&cat=88">Answer</a>';
a.match(/href="(.*)"/)[1];
var-str='';
var div=document.createElement('div');
div.innerHTML=str;
document.write(div.childNodes[0].getAttribute('href'))

为什么不能使用element.getAttribute(),我将其作为firefox扩展开发的一部分使用,我必须在不使用element.getAttribute()的情况下解析代码的某些部分。bcoz我将从ajax调用中获取元素我尝试过XML解析将元素附加到Div并解析它,但没有任何效果,所以我选择这种方式
var htmlString = 'td3...(etc)';
var regex = /href="([^"])"/;
var hrefUrl = regex.exec()[1];
console.log(hrefUrl); //?action=add&question=149&cat=88 
var a='<a href="?action=add&question=149&cat=88">Answer</a>';
a.match(/href="(.*)"/)[1];
var str = '<a href="?action=add&question=149&cat=88">Answer</a>';

var div = document.createElement('div');
div.innerHTML = str;

document.write(div.childNodes[0].getAttribute('href'))