我想獲得a
標記的href
和hash
的值。當我做通過jQuery獲取href值
$(document.body).on('click',"a",function(event){
console.log($(this));
});
我看到一個物體的東西,如
[a.internalLink, context: a.internalLink, jquery: "1.10.2", constructor: function, init: function, selector: ""…]
0: a.internalLink
accessKey: ""
attributes: NamedNodeMap
...
hash: "#abc.1.2"
...
href: "http://www.example.com/page.html#abc.1.2
...
但是,當我試圖通過console.log($(this).href)
得到的價值,它只是不工作(打印出「不確定」)。我怎麼才能得到它?
只是'this.href'或'$(this).attr('href')' – kalley