首页 > 解决方案 > 添加for循环时的ReferenceError

问题描述

ReferenceError: fetchRemoteClusters is not defined当我在我的fetchRemoteClusters函数中添加一个 for 循环时,我感到很奇怪。当我删除 for 循环并简单地执行警报或其他任何操作时,它就可以正常工作。

我的功能看起来像这样

function fetchRemoteClusters(location)
{
var select = document.getElementById("Pantheoncluster");
var options = ["1", "2", "3", "4", "5"];

for(var i = 0; i < options.length; i++) {
    var opt = options[i];
    var el = document.createElement("option");
    el.text = opt;
    el.value = opt;
    select.add(el);
   }​
}

这是我调用函数的地方

<input type="checkbox" id = "<?php echo $this->LOC2?>" name="<?php echo $this->LOC2?>" value="<?php echo $this->LOC2?>" onclick="fetchRemoteClusters('<?php echo $this->LOC2?>')"><?php echo $this->LOC2?>

这可能是什么原因造成的?请帮忙。

标签: javascriptfor-loopdom

解决方案


推荐阅读