获得HREF [英] Obtain HREF's

查看:79
本文介绍了获得HREF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


有谁知道如何让JavaScript检索存储在页面上的超链接,然后再使用它们?


提前致谢

Hi all,

Does anyone know how to get JavaScript to retrieve the hyperlinks that are stored on a page and then use them later on?

Thanks in advance

推荐答案


有谁知道如何让JavaScript检索存储的超链接在页面上然后再使用它们?
Does anyone know how to get JavaScript to retrieve the hyperlinks that are stored on a page and then use them later on?



var anchors = document.getElementsByTagName(''a'');

for(var i = 0; i< anchors。长度; ++ i)

{

alert(anchors [i] .getAttribute(''href''));

}

var anchors = document.getElementsByTagName(''a'');
for (var i = 0; i < anchors.length; ++i)
{
alert(anchors[i].getAttribute(''href''));
}


如何在点击该链接时使用它来显示或操作链接?


例如如果用户点击了存储在数组中的链接,那么他/她将被重定向,如果没有,那么他们将转到指定的页面

http://www.thescripts.com/forum/thread700874.html ,这就是我目前正在使用的atm,它要求我添加以下所有href'的:


javascript :validate(''someurl'')
and how could I use this to display or manipulate the link when that link has been clicked?

e.g. if the user has clicked upon a link which was stored in an array then he/she would be redirected and if not then they would go to the specified page

http://www.thescripts.com/forum/thread700874.html, this is what I am currently using atm which requires me to add the following to all href''s:

javascript:validate(''someurl'')


添加使用onclick而不是href的validate函数,即当你遍历链接时,添加一个onclick,它将this.href传递给validate函数。
Add the validate function using onclick rather than as a href, i.e. when you loop over the links, add an onclick which passes this.href to the validate function.


这篇关于获得HREF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆