gpt4 book ai didi

javascript - 错误: Cannot read property 'split' of undefined

转载 作者:行者123 更新时间:2023-12-01 02:06:07 24 4
gpt4 key购买 nike

我从 cookie 获取一个字符串值,其中存储了多个值。
我使用 split() 函数来分隔这些值,但我不断收到错误。这是我的代码。如果有人能帮助我解决这个问题,那将是一个很大的帮助。

var sourcez = jQuery.cookie("Source");
var mediumz = jQuery.cookie("Medium");

function utmze(eutmz) {
var utmz_val = jQuery.cookie("__utmzz");

for (var o = utmz_val, r = o.split("|"), a = 0; (a < r.length); a++) {
var t = r[a].split("=");

if (t[0] == eutmz) {
return t[1];
}
}
}

最佳答案

在执行拆分操作之前,请确保字符串不为空、不为 null 且未定义

function isValidString(input){
if(input != null && input != '' && input != undefined){
return true;
}
return false;
}
if(isValidString(input)){
input.split('=');
}

关于javascript - 错误: Cannot read property 'split' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50094456/

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