2011-09-21 14 views

Odpowiedz

14
$("a[target='_blank']").attr('target', 'sometarget');

Masz na myśli coś takiego?

0

spróbować

 $("a[target=_blank]").each(function() { 
      var href = $(this).attr("href"); // retrive href foreach a 
      $(this).attr("href", "something_you_want"); // replace href attribute with wich u want 
      // etc 
     }); 

daj mi znać, co chcesz, aby uzyskać pomoc

0

Jeśli konkretnie szuka href wartości, które mają puste wartości, a następnie wykonaj następujące czynności

$('a[href=""]').each(function() { 
    $(a).attr('href', 'theNewUrl'); 
}); 

Spowoduje to przechwycenie tylko znaczników zakotwiczonych, które mają pusty atrybut href. To nie będzie działać chociaż na kotwice brakuje tagu href

<a href="">Link 1</a> <!-- Works --> 
<a>Link 2</a> <!-- Won't work --> 

Jeśli trzeba dopasować ten ostatni następnie wykonaj następujące czynności

$('a').each(function() { 
    var href = $(this).attr('href') || ''; 
    if (href === '') { 
    $(this).attr('href', 'theNewUrl'); 
    } 
}); 
Powiązane problemy