我有一个简单的函数,似乎导致了一个未被捕获的ReferenceError:arraySort没有定义'每当调用该函数时,在这种情况下通过一个按钮,我无法理解为什么任何帮助都会很棒。
的Javascript
<script language="javascript">
var unsorted = ["Printer","Tablet","Router"];
var alphaOrder = [" ","A","a","B","b","C","c","D","d","E","e","F","f","G","g", //15
"H","h","I","i","J","j","K","k","L","l","M","m","N","n","O", //30
"o","P","p","Q","q","R","r","S","s","T","t","U","u","V","v", //45
"W","w","X","x","Y","y","Z","z","0","1","2","3","4","5","6", //60
"7","8","9","'","?","!",".","\"","<",">","@",",","#","~","=", //75
"+","-","_","/","\\"];
function arraySort(array){
var sortedArray = [];
var letterNum = 0;
var numArray = [];
function letterToNum(){
for (var elementNum = 0; elementNum < array.length; elementNum++;){
for (var alphaNum = 0; alphaNum < alphaOrder.length; alphaNum++;){
numArray[elementNum] = alphaOrder.indexOf(array[elementNum][letterNum]);
document.getElementById('tester1').innerHTML = numArray;
}
}
}
}
</script>
HTML
<button type = "button" onclick = "arraySort(unsorted)">Sort</button>
答案 0 :(得分:2)
从循环的末尾删除分号。
for (var elementNum = 0; elementNum < array.length; elementNum++) {
for (var alphaNum = 0; alphaNum < alphaOrder.length; alphaNum++) {
}
答案 1 :(得分:0)
这里很少有建议
window.onload
按照上述建议,您的错误将得到修复。
答案 2 :(得分:0)
最后我改变了
<scipt> language="javascript">
到
<scipt>
正如MuhammadJ所说,并删除了for循环末尾的分号。