gpt4 book ai didi

javascript - window.location 存储到导致错误的变量

转载 作者:行者123 更新时间:2023-11-29 18:31:50 26 4
gpt4 key购买 nike

考虑以下javascript

var str=window.location;
newArray=str.split('/');
document.write(newArray[0]);

当我在包含“window.location”的“var url”上执行拆分时,它在 firebug 控制台中导致了这个错误

TypeError
arguments: Array[2]
message: "—"
stack: "—"
type: "undefined_method"
__proto__: Error

最佳答案

您需要的是包含 url 的字符串

window.location.href

关于javascript - window.location 存储到导致错误的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7397270/

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