对于那些了解jQuery的人来说,这应该相当简单。简单的Javascript执行
我试图让这个脚本只在加载的页面上存在<span class="site-header__cart-indicator "></span>
时才运行。
这里是不变的jQuery代码:
window.setTimeout(redirectCheckout, 2000);
function redirectCheckout() {
if (!(window.location.href.includes("?1"))) {
window.location.href = "https://www.example.com/checkout";
}
}
因此,这里是我的版本的代码,但它似乎并不奏效:
if (!(window.location.includes("<span class="
site - header__cart - indicator "></span>")))
window.setTimeout(redirectCheckout, 2000);
function redirectCheckout() {
if (!(window.location.href.includes("?1"))) {
window.location.href = "https://www.example.com/checkout";
}
}
谁能告诉我为什么我的代码不工作?什么是正确的代码?
这里没有jQuery代码! – undefined