[英]Wildcard in javascript path
我需要在if语句的末尾指定带通配符的路径..就像文件系统中的*相当
if(document.location.pathname == "/project/*") { jQuery("#regbutton").css('display','none'); };
ie .. if应该以/ project /开头的所有路径触发
任何方式做到这一点w / out诉诸狂野的正则表达式的东西?
jquery解决方案也很棒..
日Thnx
这使用正则表达式,但它与正则表达式一样驯服。
if(document.location.pathname.match(/^\/project\//))
{
jQuery("#regbutton").css('display','none');
}
你可以这样做: -
String.prototype.startsWith = function(str) {return (this.match("^"+str)==str)}
if(document.location.pathname.startsWith("/project/")) {
...
}
这样,您可以随时随地使用startsWith()函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.