試圖從網址哈希中查找屬性值。jQuery從網址哈希中查找屬性
// URL
http://url.com/index.html#link
// HTML
<a href="#link" rel="3">Some link</a>
// JS
var anchor = window.location.hash.substring(1);
// Need help finding attribute value from finding the anchor
var attribute = .find('#+anchor').attr('rel'); //this needs to have a value of 3
所有幫助表示讚賞。謝謝:)
很好。現在,我怎麼能得到相反的...從rel找到#hash? – Jeffrey 2010-10-07 21:32:39
@Jeffrey - 相同類型的選擇器,例如:'$('a [rel =「something」]')。attr(「href」)' – 2010-10-07 21:33:40
謝謝,這樣做 – Jeffrey 2010-10-07 21:49:08