简体   繁体   English

简单功能在for循环外不起作用

[英]simple function doesn't work outside of for loop

This simple function doesn't work because setup_color knows nothing about #L +i 这个简单的功能不起作用,因为setup_color对#L + i一无所知

Is there any easy fix ? 有什么简单的解决方法吗?

function setup_color() {
  $("#L" + i).css('background-color', "#DCC9FF");
}

for (let i = 0; i < splitString.length; i++) {
  $temp = splitString[i];
  if ($temp > "") {
    $("#I" + i).val($temp);
    setup_color();
  }
}

pass the i as a param to the setup_color function i作为参数传递给setup_color函数

function setup_color(i){
    $("#L" + i).css('background-color', "#DCC9FF");
}

for (let i = 0; i < splitString.length; i++) {
    $temp = splitString[i];
    if ($temp > "") {
        $("#I" + i).val($temp);
        setup_color(i);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM