cuốn sách gpt4 ai đã làm

具有子字典匹配的 JavaScript 域

In lại Tác giả: Walker 123 更新时间:2023-11-28 16:42:15 26 4
mua khóa gpt4 Nike

我的代码:

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

window.onload = startup()

khởi động hàm() {
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 的正确格式是什么?

câu trả lời hay nhất

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

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

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

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

26 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress