跨浏览器更改A标签的HREF [英] Cross-browser change an A tags' HREF
问题描述
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屋!