<!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>
Js异常捕获
原文地址:https://www.cnblogs.com/nullcodeworld/p/9302365.html