原网页中已经有如下代码,且不能更更改,class标签在该页面中是唯一的:
<a href="home-uid-100.html" class="noborder">user1</a>现在我想获得a标签href中的链接uid号100,然后放到新的链接中,如:<a href="h_id=100">user1</a>js可通过a标签中的id或Name来获取href,并可通过分解来获取uid值,但是原来的代码是不可更改的,没有id,也没有name,页面中又有多个a标签,现在如何做呢?本人对js代码不是很熟,有知道的朋友麻烦贴一下代码,万分感谢!
<a href="home-uid-100.html" class="noborder">user1</a>现在我想获得a标签href中的链接uid号100,然后放到新的链接中,如:<a href="h_id=100">user1</a>js可通过a标签中的id或Name来获取href,并可通过分解来获取uid值,但是原来的代码是不可更改的,没有id,也没有name,页面中又有多个a标签,现在如何做呢?本人对js代码不是很熟,有知道的朋友麻烦贴一下代码,万分感谢!
var el = [],
_el = document.getElementsByTagName('*');
for (var i=0; i<_el.length; i++ ) {
if (_el[i].className == n ) {
el[el.length] = _el[i];
}
}
return el;
}
var classBlack = getElementsByClassName('A'); var url = classBlack[i].href ;以上是我试写的代码,不知道对不对?下面就写不下去了,各位能不能贴一下代码。我希望js代码就直接地嵌到新的a标签href中,如:
<a href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(blog=window.open('http://www5.bolaa.com/CommendBlog/SmallLogin.aspx?title='+escape(d.title)+'&newspath='+escape(d.location.href)+'&subtitle='+escape(t),'bolaa','width=400px,height=400px'));blog.focus();" title="bbb"><span></span></a>
var val = items[i].getAttribute('href');
}orfor(i in items){
var val = items[i].href;
}
var value = "";
var controllist = document.getElementsByTagName("a");
for (var i = 0; i < controllist.length; i++) {
var control = controllist[i];
if (control.getAttribute("class") == "noborder") {
value = control.getAttribute("href");
var re = /uid\-([^\.]*)/i;
var r = value.match(re);
value = r[1];
break;
} }
value 就是你要的值
var value = "";
function getElementsByClassName(n) {
var el = [],
_el = document.getElementsByTagName('*');
for (var i=0; i<_el.length; i++ ) {
if (_el[i].className == n ) {
value = _el[i].href;
var re = /uid\-([^\.]*)/i;
var r = value.match(re);
value = r[1];
break;
}
}
return el;
}
function get() {
var classBlack = getElementsByClassName('noborder');
alert("value = " + value);
}
window.onload = get
</script>