跨浏览器更改A标签的HREF [英] Cross-browser change an A tags' HREF

查看:207
本文介绍了跨浏览器更改A标签的HREF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来我无法在Javascript参考中找到 document.getElementById()。href ,有很多站点说要用这个来改变a的href链接。这安全吗?它可以在所有浏览器中工作吗?或者我应该已经准备好了我的其他链接,并在不再需要时替换旧链接?



我只有2个可能的值,在用户执行的最后一个动作上,删除或恢复。所以我想替换这个链接而不是改变它并不是什么负担。我宁愿改变它,如果它可以在所有浏览器中运行的话。



谢谢

解决方案

你不能在任何引用中找到它,因为它不是一个单独的构造,而是两个组合。



使用 document.getElementById方法来获取特定的元素,if该元素是一个定位标记,您可以使用 href属性来设置网址。



两者均在 DOM级别1规范,因此它们可安全地用于任何不超过十年历史的浏览器,并且大部分都比较旧也是。


it seems I can not find document.getElementById().href in the Javascript reference, there are a lot of sites saying to use this to change the href of a link. Is this safe? Will it work in all browsers? Or should I just already have my other link ready and replace the old one when it is no longer needed?

I only have 2 possible values I will for the link, depending on the last action performed by the user, either "delete" or "revive". So I guess replacing the link rather than changing it would not be much of a burden. I would rather change it if it will work in all browsers though.

Thanks

解决方案

You can't find it in any reference, as it's not a single construct, it's the combination of two.

Use the document.getElementById method to get a specific element, and if that element is an anchor tag, you can use the href property to set the URL.

Both are specified in the DOM level 1 specification, so they are safe to use in any browser that isn't more than a decade old, and most that are a bit older too.

这篇关于跨浏览器更改A标签的HREF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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