我正在寻找以下内容的jQuery翻译:
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;
taken from the following site:
http://articles.sitepoint.com/article/standards-compliant-world/3
我从这样的东西开始,但不知道如何搜索rel属性(不循环所有锚点):
$(document).ready(function () {
$( body ).find( a ).findTheRelTagWithExternalValue;
});
Thanks,
--Ed