最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using JQuery to Hide links based on URL value - Stack Overflow

programmeradmin7浏览0评论
jQuery(".rfr-col-title").css("display", "none");

I would like to hide this class .rfr-col-title if the url contains abc/Lists/abc/DispForm.aspx?ID=

http://win-e98sopqc735/abc/Lists/abc/DispForm.aspx?ID=

jQuery(".rfr-col-title").css("display", "none");

I would like to hide this class .rfr-col-title if the url contains abc/Lists/abc/DispForm.aspx?ID=

http://win-e98sopqc735/abc/Lists/abc/DispForm.aspx?ID=

Share Improve this question edited Sep 9, 2011 at 18:47 rlemon 17.7k14 gold badges94 silver badges126 bronze badges asked Sep 9, 2011 at 15:57 user472285user472285 2,6745 gold badges38 silver badges55 bronze badges 2
  • 2 The url of the page or the link? – epascarello Commented Sep 9, 2011 at 16:04
  • The fact that he/she wants to hide an entire class if the "url contains.." would lead me to believe that it's the location.href not a.href, otherwise what would be the point of hiding an entire class of links if one contains said string. – rlemon Commented Sep 9, 2011 at 16:10
Add a ment  | 

4 Answers 4

Reset to default 3

The jQuery way would be to do an attribute selector:

$('a[href*="abc/Lists/abc/DispForm.aspx?ID="]').hide();

The *= means "contains".

You could also use ^= for "begins with" or $= for "ends with".

Example: http://jsfiddle/dQFJe/

Attribute selector docs: http://api.jquery./category/selectors/attribute-selectors/

Edit

I just reread the question. Are you talking about the url of the page? If so, you have to do an if statement on a window location match:

if(window.location.href.match("abc/Lists/abc/DispForm.aspx?ID=")) {
    $(".rfr-col-title").hide();
}

Example: http://jsfiddle/EyVr4/

if(window.location.href.indexOf("abc/Lists/abc/DispForm.aspx?ID=") > -1) {
  jQuery(".rfr-col-title").hide();
}

jQuery do have a attribute contain selector. So you can do this:

$('a[href*="abc/Lists/abc/DispForm.aspx?ID="]').hide();

Instead of .css('display', 'none') use .hide()

How about this

var url = window.location.pathname;


if ("url:contains('abc/Lists/abc/DispForm.aspx?ID=')"){
    $(".rfr-col-title").hide();

}
发布评论

评论列表(0)

  1. 暂无评论