首页 文章

选择<a>哪个href以某个字符串结尾

提问于
浏览
630

是否可以使用jQuery选择href以"ABC"结尾的所有 <a> 链接?

例如,如果我想找到这个链接 <a href="http://server/page.aspx?id=ABC">

4 回答

  • 1473
    $('a[href$="ABC"]')...
    

    选择器文档可在http://docs.jquery.com/Selectors找到

    对于属性:

    = is exactly equal
    != is not equal
    ^= is starts with
    $= is ends with
    *= is contains
    ~= is contains word
    |= is starts with prefix (i.e., |= "prefix" matches "prefix-...")
    
  • 3
    $('a[href$="ABC"]:first').attr('title');
    

    这将返回第一个链接的 Headers ,该链接具有以“ABC”结尾的URL .

  • 13
    $("a[href*='id=ABC']").addClass('active_jquery_menu');
    
  • 18
    $("a[href*=ABC]").addClass('selected');
    

相关问题