2015-10-06 82 views
0

我正在学习考试,我自己做了一些示例问题。我遇到了Uncaught TypeError:document.getElementByID不是函数问题。document.getElementByID不是函数快速修复

这里是我的代码:

<script> 
function checkValidity(){ 
    //Create variable to check for errors 
    var input = document.getElementByID('myID').value; 

    if(input < 0){ 
     document.getElementByID('errorCheck').textContent = 'The value must be a positive integer'; 
    }else if(ifNaN(input)){ 
     document.getElementByID('errorCheck').textContent = 'Not a number. The value must be a positive integer.'; 
    }else if(input == null){ 
     document.getElementByID('errorCheck').textContent = 'Please input a value.'; 
    } else{ 
     document.getElementByID('errorCheck').textContent = 'Valid number.'; 
    } 
} 

document.getElementByID('validateid').onclick = checkValidity; 

这对我大喊大叫,在这行代码说它是无效的。

document.getElementByID('validateid').onclick = checkValidity; 

我知道它的一个小错误。如果有人指出,我会很感激。

+0

'isNaN',而不是'ifNaN'。 – 1252748

回答

4

您正在寻找document.getElementById,小写字母d。

+0

我很感激。我输错了一次,Sublime为我完成了其余的一些。不能相信我没有听到。 – Logan

+1

@Logan由于这个或其他相同的答案明显解决您的问题,请接受一个,所以这被标记为已回答。 – bgse

2

看起来像一个错字。您需要做:

document.getElementById('errorCheck') 

小写'd'。这里是参考link