我希望能够检查 url 是否包含单词目录。
这就是我正在尝试的...
$(document).ready(function () {
if (window.location.href.indexOf("catalogue"))
{
$("#trail").toggle();
}
});
该网站的网址可能是..
http://site.co.uk/catalogue/
要么
http://site.co.uk/catalogue/2/domestic-rainwater.html
等等。
但它不起作用。有人可以指出我哪里出错了吗?
最佳答案
尝试:
if (window.location.href.indexOf("catalogue") > -1) { // etc
indexOf 不返回真/假,它返回搜索字符串在字符串中的位置;如果未找到,则为 -1。
关于javascript - jquery如何检查url是否包含单词?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10243576/