gpt4 book ai didi

具有子字典匹配的 JavaScript 域

转载 作者:行者123 更新时间:2023-11-28 16:42:15 24 4
gpt4 key购买 nike

我的代码:

const checkoutUrl = 'https://example.com/checkout/*'

window.onload = startup()

function startup() {
if (window.location.href == checkoutUrl) {
// DO something
//call a function
}
}

但实际的 URL 是:

'https://example.com/checkout/?x=0&spni=Random_Number&ID=Some_Random_Number_Always'

所以 (window.location.href == checkoutUrl) 不起作用。 checkoutUrl 的正确格式是什么?

最佳答案

检查字符串是否以 checkoutUrl 开头。为此,您需要从 checkoutUrl 中删除 *,因为没有通配符匹配。

const checkoutUrl = 'https://example.com/checkout/';

if (window.location.href.startsWith(checkoutUrl))

关于具有子字典匹配的 JavaScript 域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61000828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com