[英]Using JQuery to Hide links based on URL value
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= 如果网址包含abc / Lists / abc / DispForm.aspx?ID =,我想隐藏此类.rfr-col-title
http://win-e98sopqc735/ abc/Lists/abc/DispForm.aspx?ID= http:// win-e98sopqc735 / abc / Lists / abc / DispForm.aspx?ID =
The jQuery way would be to do an attribute selector: jQuery的方式是做一个属性选择器:
$('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.net/dQFJe/ 示例: http : //jsfiddle.net/dQFJe/
Attribute selector docs: http://api.jquery.com/category/selectors/attribute-selectors/ 属性选择器文档: http : //api.jquery.com/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
语句:
if(window.location.href.match("abc/Lists/abc/DispForm.aspx?ID=")) {
$(".rfr-col-title").hide();
}
Example: http://jsfiddle.net/EyVr4/ 示例: http : //jsfiddle.net/EyVr4/
if(window.location.href.indexOf("abc/Lists/abc/DispForm.aspx?ID=") > -1) {
jQuery(".rfr-col-title").hide();
}
How about this 这个怎么样
var url = window.location.pathname;
if ("url:contains('abc/Lists/abc/DispForm.aspx?ID=')"){
$(".rfr-col-title").hide();
}
jQuery do have a attribute contain selector . jQuery确实具有包含选择器的属性 。 So you can do this:
因此,您可以执行以下操作:
$('a[href*="abc/Lists/abc/DispForm.aspx?ID="]').hide();
Instead of .css('display', 'none')
use .hide()
代替
.css('display', 'none')
使用.hide()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.