2

我的代码是这样的

$("a[href]").each(function () {
    if ($(this).attr("href").toLowerCase().indexOf("javascript:") != 0 &&     $(this).attr("class") != "to-top")
   {
      $(this).attr("href", new URI($(this).attr("href")).removeQuery("at").addQuery("at", $.cookies.get('ACCT_TYPE') != null ? $.cookies.get('ACCT_TYPE') : "erhverv"));
  }
});

现在我想避免这种情况下的特定链接。“a”链接属于“税收转换”类。有没有捷径可以实现这一目标?

4

4 回答 4

4

正如@vivek 所说,使用以下not功能:

$('a[href]').not('.tax-switch').each(

这将选择所有没有“tax-switch”类的锚。

于 2013-01-01T10:27:32.033 回答
3

试试这个代码,工作小提琴

$("a[href]:not(.tax-switch)").each(function () {
   $("#myDIV").append('<p>'+ $(this).html()+'</p>');
});
于 2013-01-01T11:52:10.460 回答
1

您可以使用 jquery 而不是选择器。 http://api.jquery.com/not-selector/

于 2013-01-01T10:20:37.087 回答
0

使用filter()

$('a[href]').filter(function(){
    return !$(this).hasClass('tax-switch');
}).each(function(){
    // do your stuff
});

参考:

  • filter().
于 2013-01-01T10:25:55.877 回答