0
這段代碼獲得在所有瀏覽器的路徑 - 除了IE7,當它返回完整的URL獲取與jQuery .attr(相對路徑)財產與IE7
$(selector).attr('href');
如何適應這個代碼總是返回路徑?
/foo/bar/x.html
不
http://www.sample.com/foo/bar/x.html
這段代碼獲得在所有瀏覽器的路徑 - 除了IE7,當它返回完整的URL獲取與jQuery .attr(相對路徑)財產與IE7
$(selector).attr('href');
如何適應這個代碼總是返回路徑?
/foo/bar/x.html
不
http://www.sample.com/foo/bar/x.html
$(selector).attr('href').replace('http://'+window.location.hostname,'')
嗯,看起來像IE7是做正確的* *唯一的瀏覽器。原始屬性是什麼樣的? – 2011-10-17 12:29:16
這是一條路徑'link` – Boz 2011-10-17 12:32:59