在javascript中添加reg exp来确定url是否在/之后有任何字符

Adding reg exp in javascript to determine if url has any character after /

本文关键字:是否 之后 字符 任何 url javascript 添加 reg exp      更新时间:2023-09-26

我想添加一个正则表达式来确定url中是否包含"/"之后的任何字符。现在这个正则表达式只是在寻找"a"。我似乎不能让任何正则表达式的连接工作。

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

您可以使用:

var b = /services'/./.test( document.location.href );
if (b)
   alert("there is a character after services/");
$(function() {
  if (!document.location.href.match(/'/$/) { // $ matches only if the preceding character is the end of the string
    <your code here>
  }
});

相关文章: