gpt4 book ai didi

javascript - 我收到意外的循环错误

转载 作者:行者123 更新时间:2023-12-03 10:21:41 25 4
gpt4 key购买 nike

function setL(sname, svalue) {
localStorage.setItem(sname, svalue)
}

function getL(sname) {
if (!localStorage.getItem(sname)) localStorage.setItem(sname, "")
return localStorage.getItem(sname)
}

function delL(sname) {
localStorage.removeItem(sname)
}


for (i = 0; i < options.length; i++) {
if (getL(options[i]) == null) {} else {
$("#" + options[i]).attr("value", getL(options[i]));
$(options_target[i]).css(options_change[i], getL(options[i]));
}
};

getLlocalstorage 获取值。所以我的循环所做的是, for

  var options = ["bg_color", "bottom_bar_color", "button_color", "dialog_color", "notify_color", "button_text_color"];
var options_target = ["body", "#bottom", ".ugly-button", ".dialog", ".notification .notification-body", ".ugly-button"];
var options_change = ["background", "background", "background", "background", "color"];

它使用“选项”数组的值(设置为本地存储)为适当的元素设置适当的 css 值。

这在一天前还可以工作..但现在我遇到了一个意外的错误..这是

Uncaught TypeError: Cannot read property 'replace' of undefined

我的代码中没有替换,所以任何人都可以帮助我调试代码并修复它(如果可能的话)吗?

最佳答案

var options = ["bg_color", "bottom_bar_color", "button_color", "dialog_color", "notify_color", "button_text_color"];
var options_target = ["body", "#bottom", ".ugly-button", ".dialog", ".notification .notification-body", ".ugly-button"];
var options_change = ["background", "background", "background", "background", "color"];

选项长度为 6。options_target 长度为 7。options_change 长度为 5。

所以:i 从 0 到 5。

$(options_target[i]).css(options_change[i], getL(options[i]));

当我是 5 时:options[i] 有值,options_change[i] 未定义,因为它超出范围...

关于javascript - 我收到意外的循环错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29598428/

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