我添加了像這樣添加與jQuery的多個環節
$("a").filter(function() {
var ignoreLink =
this.hostname == location.hostname // disregard same domain
|| this.href.match(/^(mailto|tel|javascript)\:/)
return !ignoreLink;
}).addClass("externalanchor").attr("target", "_blank");
上面的代碼工作正常過濾功能第三方鏈接的背景圖像需要的類別,現在我有一個要求,說一些鏈接應該是內部的ex:
<p><a href="https://www.google.com/" target="_blank">Email URL</a></p>
<p><a href="https://github.com/" target="_blank">Google</a></p>
<p><a href="https://www.w3schools.com" target="_blank">Google</a></p>
<p><a href="https://www.codecademy.com" target="_blank">Google</a></p>
我的問題是如何添加一個類爲這個鏈接單獨與一個dom只改變與jquery。
你想添加一個類元件,其有目標空白?或者你想添加目標空白和一個類與外部網站的元素?我做了兩種方式,告訴我你想要什麼 – TriForce
$(「a [href =」https://www.google.com/「], \t \t \t \t [href =」https://github.com/「], \t \t \t \t [HREF =」 https://www.w3schools.com 「], \t \t \t \t [HREF =」 https://www.codecademy.com 「]」).addClass( 「無外部」); \t});我需要像這樣的東西 – prad
像'$('a [href^=「http」')。addClass('no-external')'? – Przemek