开发者

Wildcard in javascript path

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜