如何在使用JQuery时停止jsdom自动sorting的href结果?

这个脚本使用jsdom和jquery来获取标签的href属性的值。 出于某种原因,它出来完全合格,相对于我正在运行脚本的path。我怎样才能得到只有 href值,不完全合格?

var currentDoc = jsdom.jsdom('<html><head><title>href test</title></head><body><p><a href="test.html">Test</a></p></body></html>';, null, {}); var window = currentDoc.createWindow(); jsdom.jQueryify(window, 'jquery-1.4.2.min.js' , function() { console.log(window.$('a')[0]['href']); }); 

(代码片段也在https://gist.github.com/2355968 )

您想要使用getAttribute而不是仅字段存取器。

 var someLink = document.createElement("A"); someLink.href = "/foo"; someLink.href; // => "http://whatever.com/foo" someLink.getAttribute("href"); // => "/foo"