在javascript中添加正则表达式以确定url是否在/之后有任何字符

时间:2014-06-27 15:40:38

标签: javascript jquery regex url any

我想添加一个正则表达式来确定一个网址是否包含" /"之后的任何字符。在网址中。现在这个正则表达式正在寻找" a"。我似乎无法使正则表达式连接起作用。

$(function() {
    if ( document.location.href.indexOf('services/a') > -1 ) {
      $(window).scrollTop(450)
    }
});

2 个答案:

答案 0 :(得分:0)

您可以使用:

var b = /services\/./.test( document.location.href );

if (b)
   alert("there is a character after services/");

答案 1 :(得分:0)

$(function() {
  if (!document.location.href.match(/\/$/) { // $ matches only if the preceding character is the end of the string
    <your code here>
  }
});

应该有用。