Js异常捕获
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> function demo(){ try{ alert(str); }catch(e){ alert(e); } } demo(); </script> <form> <input id="txt" type="text"/> <input id="btn" type="button" onclick="demo1()" value="按钮" /> </form> <script> function demo1(){ try{ var e=document.getElementById("txt").value; if(e==""){ throw "请输入"; } }catch(e){ alert(e); } } </script> </body> </html>
本文来自博客园,作者:一纸年华,转载请注明原文链接:https://www.cnblogs.com/nullcodeworld/p/9302365.html