昨天我问了类似的问题,所以我知道如何将所有外部链接重定向到我的主页。重定向除了我不想重定向的所有外部链接
// when the document is ready
$(document).ready(function() {
// iterate over all the anchor tags
$("a").each(function() {
// if the current link's href doesn't already contain 'www.kownleg.com'
if (this.href.indexOf('www.kownleg.com') === -1) {
// change current link to home page
this.href = 'http://www.kownleg.com';
}
});
});
但现在我要排除所有这些我不想重定向到我的主页,像facebook.com & twitter.com的联系,我试图让该链接的另一个条件,我不要不想重定向,但它不起作用。然后我试图改变indexOf()
与text()
但仍然无法正常工作。
这里是二值编码,我试过,但我失败了
// when the document is ready
$(document).ready(function() {
// iterate over all the anchor tags
$("a").each(function() {
// if the current link's href doesn't already contain 'www.kownleg.com'
if (this.href.indexOf('www.kownleg.com') === -1) {
// change current link to home page
this.href = 'http://www.kownleg.com';
}
if (this.href.indexOf('www.facebook.com') === -1) {
// change current link to home page
this.href = 'http://www.facebook.com';
}
if (this.href.indexOf('www.twitter.com') === -1) {
// change current link to home page
this.href = 'http://www.twitter.com';
}
});
});
另一个问题:
// when the document is ready
$(document).ready(function() {
// iterate over all the anchor tags
$("a").each(function() {
// if the current link's href doesn't already contain 'www.kownleg.com'
if (this.href.indexOf('www.kownleg.com') === -1) {
// change current link to home page
this.href = 'http://www.kownleg.com';
}
if (this.href.text('www.facebook.com') === -1) {
// change current link to home page
this.href = 'http://www.facebook.com';
}
if (this.href.text('www.twitter.com') === -1) {
// change current link to home page
this.href = 'http://www.twitter.com';
}
});
});
和所有的类似的可能性......但仍然没有为我工作。
不工作.. :( – 2013-03-16 18:54:35