相关疑难解决方法(0)

Javascript未捕获引用错误函数未定义

检查小提琴以查看发生的故障.

当我将数据(即使我将其留空)添加到文本框并尝试单击"添加"时,它不会执行任何操作.

打开Chrome和Firefox控制台都会给我同样的错误,它说"changeText2()"没有定义.

我怎样才能解决这个问题?我已经多次遇到过这个错误,而且大多数都是非常奇怪的解决方法,但我不确定避免它的方法或我甚至做错了什么.

似乎删除全局变量声明会在大多数情况下修复它,但是,在这种情况下我需要它们并且宁愿知道为什么以及如何发生此错误.

非常感谢任何和所有的帮助.

使用Javascript:

var list = document.getElementById('deliveryIdArray');
var names = [];

function changeText2() {
    var deliveryIdentification = document.getElementById('deliveryIdentification').value;
    names.push(deliveryIdentification);//simply add new name to array;
    //array changed re-render list
    renderList();
}

function renderList(){
    while (list.firstChild) {
        list.removeChild(list.firstChild);
    }
    //create each li again
    for(var i=0;i<names.length;i++){
        var entry = document.createElement('li');
        entry.appendChild(document.createTextNode(names[i]));
        var removeButton = document.createElement('button');
        removeButton.appendChild(document.createTextNode("remove"));
        removeButton.setAttribute('onClick','removeName('+i+')');
        entry.appendChild(removeButton);
        list.appendChild(entry);
    }
}


function removeName(nameindex){
    names.splice(nameindex,1);
    //array changed re-render list
    renderList();
}

function getDeliveries(){
    return names;
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<b>Number(s): </b>
    <input …
Run Code Online (Sandbox Code Playgroud)

html javascript

27
推荐指数
2
解决办法
16万
查看次数

标签 统计

html ×1

javascript ×1