我想添加一个正则表达式来确定一个网址是否包含" /"之后的任何字符。在网址中。现在这个正则表达式正在寻找" a"。我似乎无法使正则表达式连接起作用。
$(function() {
if ( document.location.href.indexOf('services/a') > -1 ) {
$(window).scrollTop(450)
}
});
答案 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>
}
});
应该有用。