开发者

Wildcard in javascript path

开发者 https://www.devze.com 2023-02-06 18:47 出处:网络
I need to specify a path with wildcard on the end of an if statement.. like the equivalent of * in the filesystem

I need to specify a path with wildcard on the end of an if statement.. like the equivalent of * in the filesystem

if(document.location.pathname开发者_如何学Python == "/project/*") { jQuery("#regbutton").css('display','none'); };

ie.. the if should fire for all paths that start with /project/

any way to do this w/out resorting to wild regex stuff?

jquery solution would be great too..

thnx


This uses a regex, but it's about as tame as regexes get.

if(document.location.pathname.match(/^\/project\//))
{
    jQuery("#regbutton").css('display','none');
}


You can do something like this:-

String.prototype.startsWith = function(str) {return (this.match("^"+str)==str)}

if(document.location.pathname.startsWith("/project/")) {
   ...
} 

This way, you can keep using startsWith() function anytime you want next time.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号