Javascript 错误处理:try throw catch
2016-11-02 11:38
771 查看
<body> <p>请输入1~10的数字:</p> <input id="input" type="text" onfocus="clearAll(this)"> <input type="button" value="校验" onclick = "check()"> <p id="msg"></p> </body>
<script> function check(){ try{ var x = document.getElementById("input").value; if(x==""){throw "值为空!";} if(isNaN(x)){throw "不是数字!";} if(x<1){throw "数字太小!";} if(x>10){throw "数字太大!";} } catch(error){ var y = document.getElementById("msg"); y.innerHTML = "错误:" + error ; } } function clearAll(x){ x.value=""; } </script>
相关文章推荐
- JavaScript 错误处理, Throw、Try 和 Catch入门
- JavaScript入门之错误—Throw.Try.Catch
- 从零开始学C++之异常(一):C语言错误处理方法、C++异常处理方法(throw, try, catch)简介
- (六)JavaScript之[Regular Expression]与[错误(try, catch, throw)]
- [转贴]从零开始学C++之异常(一):C语言错误处理方法、C++异常处理方法(throw, try, catch)简介
- JavaScript 1.7 错误try catch throw
- JavaScript 错误 - Throw、Try 和 Catch
- JavaScript错误_throw、try和catch
- JavaScript错误-throw、try{ } catch(err){ }
- JavaScript——错误(throw、try、catch)
- JavaScript基础1:JavaScript 错误 - Throw、Try 和 Catch
- JavaScript 错误 - Throw、Try 和 Catch
- 错误处理try-catch,异常抛出throws、throw
- JavaScript 错误 - Throw、Try 和 Catch
- JavaScript 错误 - throw、try 和 catch
- 从零开始学C++之异常(一):C语言错误处理方法、C++异常处理方法(throw, try, catch)简介
- JavaScript 错误 - Throw、Try 和 Catch
- Javascript错误处理——try...catch
- JavaScript 错误 - throw、try 和 catch
- 【JavaScript】错误处理:try......catch