使用jQuery获取锚元素的绝对URL [英] Getting an anchor element's absolute URL with jQuery
本文介绍了使用jQuery获取锚元素的绝对URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出一个锚元素(带有类似$("a:first")
的元素),如何获得锚指向的绝对URL?
Given an anchor element (with something like $("a:first")
), how do you get the absolute URL that the anchor points to?
推荐答案
如果您使用的是jQuery 1.6+,则可以使用.prop()
:
If you're using jQuery 1.6+, you can use .prop()
:
$("a:first").prop("href")
在1.6之前,您可以直接在DOM元素上访问href
属性:
Prior to 1.6, you can access the href
property directly on the DOM element:
$("a:first")[0].href;
这篇关于使用jQuery获取锚元素的绝对URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文