如果 URL 包含 "invt",我想要执行 up() 函数。
到目前为止,我的代码如下:
if(window.location.pathname == "/invt/"){
alert("invt");
}
然而,对我来说这并没有警示。你有什么想法吗?
多亏了下面的答案,我现在已经解决了这个问题。
考虑以下内容:
$(document).ready(function () {
if(window.location.href.indexOf("invt") > -1) { //checks url for "invt" (all products contain this)
up();
return;
}
});
"/invt/"
,前后没有其他文本。请参考下面的答案以了解.indexOf()
的用法。 - MDEV