标签:== demo 文本 异常 条件 || _id cat 捕获异常
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>捕获异常</title> </head> <script type="text/javascript"> function my_func(){ try{ x=document.getElementById("input_id").value; alert(x); if(x==""||x==null) throw "非空"; if(isNaN(x)) throw "必须是数字"; if(x<5) throw "数字太小"; if(x>10) throw "数字太大"; else throw "输入正确"; }catch(err){ document.getElementById("demo").innerHTML="提示:"+err; } } </script> <body> <p>请输入5——10之间的数字</p> <input type="text" id="input_id"> </input> <button type="button" id="button_id" onclick="my_func()">确定</button> <p id = "demo"></p> </body> </html>
标签:== demo 文本 异常 条件 || _id cat 捕获异常
原文地址:https://www.cnblogs.com/zxrxzw/p/10792589.html