2011-01-25 112 views
1

我需要在的末尾指定用通配符路径if语句.. 像*的文件系统中的等价通配符在javascript路径

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

即..中频应该火的所有路径开始/项目/

任何方式做到这一点瓦特/出诉诉野生正则表达式的东西?
jQuery的解决方案将是伟大的太..

日Thnx

回答

4

它使用正则表达式,但它是我们所驯服的正则表达式得到。

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

工作流畅如丝..多thanx(这真的是非可怕的正则表达式:) – Joseph 2011-01-25 03:45:56

+0

@约瑟夫:我编辑了我的答案;我忘了你不需要在`location.pathname`上调用`toString()`(因为它已经是一个字符串了)[尽管你需要在``location`本身上调用`toString()`](https: //developer.mozilla.org/en/DOM/window.location#Use_as_a_string)。 – 2011-01-25 03:55:08

0

你可以做这样的事情: -

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

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

这样,您就可以继续使用startsWith()函数,只要你愿意下一次。