我知道,我可以这样做^ =以查看是否有ID的东西开始,我尝试使用,对于这一点,但它没”将不起作用......基本上,我检索的URL,我想设置为以某种方式开始的路径名元素的类...
所以,
var pathname = window.location.pathname; //gives me /sub/1/train/yonks/459087
我想确保所有以/分/ 1开始的路径,我可以设置一个类的元素...
if(pathname ^= '/sub/1') { //this didn't work...
...
'/^\/sub \/1。* $/gi.test(pathname)'将返回一个布尔值作为谓词。 – 2016-06-23 14:12:19
如果你沮丧年以后来到这里(我自己)的[原创与复制后的Javascript StartsWith(http://stackoverflow.com/questions/646628/how-to-check-if-a-string-startswith-另一个字符串)提供了一个非常简洁的答案,使用Ecmascript 6 startWith()函数,似乎有最好的表现。 – theFreedomBanana 2016-09-22 07:36:19