jquery - 如果 jQuery 中的 url 包含 "x"如何执行函数

标签 jquery function url contains

我想执行函数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/

相关文章:

jquery 追加到列表的前面/顶部

javascript - 使用 JavaScript 调整图像大小并保存到磁盘

c - 在 C 中定义和实现 pow 函数的位置在哪里?

json - 如何使用 OCaml Url 和 Cohttp

iPhone:fb://... 打开 Premier Inn 应用程序的 URL,而不是 Facebook

python - Go 中的 urllib.quote() ?

javascript - 将相邻的 <p> 元素包装到 <div> 中

javascript - 如何按多个项目搜索/过滤列表?

c++ - 无法计算字符类型的数量

c++ - std::bind 是否实现了 std::ref 和 std::cref 来消除函数调用的歧义?