Tom*_*kay 2 javascript jquery conditional if-statement
如何获取文档URL并将其与条件分支进行比较?
伪代码:
If document url = "../products.html"
Then do this piece of code();
Run Code Online (Sandbox Code Playgroud)
如果你正在使用加载的html,你可以试试
if(window.location.pathname == "products.html"){
//do something here
}
Run Code Online (Sandbox Code Playgroud)
location.pathname返回该位置指定的文件名或路径.
此外,您可以通过获取文件名
var p = window.location.pathname.split("/");
var filename = p[p.length-1];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5263 次 |
| 最近记录: |