【发布时间】:2015-10-15 10:24:46
【问题描述】:
我看过一个类似的问题,但是它获取了每个类的 href 属性,我想要每个元素的 href 属性。然后我想将其更改为我指定的一个链接。他们的解决方案如下所示:
var a,b,c,d, len;
a = document.getElementsByClassName("item title_link");
len = a.length;
b = a[i].getAttribute('href');
c = b.replace("#", "");
d = "http://www.domainname.com/index/" + c + "/get";
console.log(d); //just to check them out
}
//window.location.href = d;
//or whatever you wanted to do with that...
有什么方法可以替换每个属性而不是只替换指定的类?
【问题讨论】:
-
是
getElementsByTagName()你在找什么?
标签: javascript jquery href userscripts