1

我有我想根据http://www.mywebsite.com/post/根目录中的所有页面执行的代码

我将使用什么方法来定位 url 的 post 部分,无论代码执行后会发生什么?

我的代码是:

var url = document.location.href;
if (url = 'http://www.mywebsite.com/post/') {
//do something
}

我想通了,成功了!

以下是解决方案:

var url = document.location.href;
if (url.indexOf("post") > 0) {
//do something
}

最终,我想像通配符一样使用这个网址“http://www.mywebsite.com/post/”。我该怎么做?

4

0 回答 0