基于URL参数的方法
我想根据 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/”。我该怎么办?
I have code which I would like to execute based on all the pages in the root directory of http://www.mywebsite.com/post/
What method would I use to target the post portion of the url, that way no matter what comes after it the code executes?
my code is:
var url = document.location.href;
if (url = 'http://www.mywebsite.com/post/') {
//do something
}
I figured it out and success!
Below is the solution:
var url = document.location.href;
if (url.indexOf("post") > 0) {
//do something
}
Ultimately I would like to use this url "http://www.mywebsite.com/post/" like a wildcard. How do I this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论