0

「switchステートメント」の書き方を理解しようとしているので、特定の(「yourdomain.com」と呼びましょう)外部URLが一致すると、新しいウィンドウで開きません。残りは開きます。誰か教えてくれませんか?

jQuery(function ($) {
    $('a[href^="http://"]')
        .not('[href*="http://mydomain.com"]')
        .attr('target', '_blank');

例えば

mydomain.com = これは私の URL であるため、新しいウィンドウは開きません

yourdomain.com = 外部 URL であっても、この特定の URL は新しいウィンドウで開きません

anyotherdomain.com = 上記以外のすべての外部 URL が新しいウィンドウで開きます

4

2 に答える 2

1
$(function() {
     var elms = $('a[href^="http://"]');
     $.each(elms, function() {
          var current_link = $(this).attr("href");
          if (current_link == "yoururl") {
               $(this).attr('target', '_blank');
          }
     });
});

これは役に立ちますか?

于 2012-10-26T01:57:22.297 に答える
1

別の.not()を追加して解決しました

jQuery(function ($) {
    $('a[href^="http://"]')
        .not('[href*="http://mydomain.com"]').not('[href*="http://yourdomain.com"]')
        .attr('target', '_blank');
于 2012-10-26T02:18:00.657 に答える