下面的这段文字是我的代码 它运作良好,当我输入空/ NUM低/高NUM 然而,当我输入字符串它不能很好地工作我不能修复我的错误
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Show error message depending on input value by using try/catch/throw</h1>
<input type="text" id="input1">
<button id="btn1" onclick="showR()">Show the result</button>
<p id="demo1"></p>
<script type="text/javascript">
function showR(){
var x;
x= document.getElementById('input1').value;
//x= Number(x);
try{
if(x=="")throw "empty";
if(x==isNaN(x))throw "not a number";
x= Number(x);
if(x<5)throw "too low";
if(x>10)throw "too high";
document.getElementById(demo1).innerHTML=x;
}catch(err){
document.getElementById('demo1').innerHTML = "input is : " + err;
}
document.getElementById('input1').innerHTML='hi';
}
</script>
</body>
</html>
该错误信息是 输入:类型错误:无法设置为null 的特性“的innerHTML”的原因是什么,我怎么能解决这个问题
'if(x == isNaN(x))'总是false ...摆脱'x ==' –
下次使用[JSHint](http://jshint.com/)。它为您节省了大量时间和工作,并减少了提问这类错字相关问题的需求。 – Xufox