==小例子1
==JS中允许将"." 替换成 “[ ]”
document.getElementById('btn1') 写成 document['etElementById']('btn1')
==25 26 27课
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> <script> function myfun(){ try{ var e=document.getElementById("demo2").value; if(e=="") throw "值为空了"; if(isNaN(e)) throw "非数字"; if(e>10) throw "大于10了"; } catch(err){ var y= document.getElementById ("mess2"); y.innerHTML ="错误:" + err + "。"; } } </script> </head> <body> <h1>我的第一个查询</h1> <p>请输出一个 5 到 10 之间的数字:</p> <input id ="demo2" type="text"> <button type="button" onclick="myfun()">请输入数字</button> <p id="mess2"></p> </body> </html>
菜鸟教程在线工具
http://www.runoob.com/try/try.php?filename=tryjs_throw_error