我想执行函数up();如果 url 包含“invt”。
到目前为止我有这个:
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;
}
});
最佳答案
试试这个:
if ( window.location.pathname.indexOf('invt') >= 0 )
{
alert("invt");
}
关于jquery - 如果 jQuery 中的 url 包含 "x"如何执行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18595134/