• 吴裕雄--天生自然 JAVASCRIPT开发学习: 错误


    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    <script>
    var txt="";
    function message(){
        try {
            adddlert("Welcome guest!");
        }
        catch(err) {
            txt="本页有一个错误。
    
    ";
            txt+="错误描述:" + err.message + "
    
    ";
            txt+="点击确定继续。
    
    ";
            alert(txt);
        }
    }
    </script>
    </head>
    <body>
    
    <input type="button" value="查看消息" onclick="message()" />
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    <p>不管输入是否正确,输入框都会再输入后清空。</p>
    <p>请输入 5 ~ 10 之间的数字:</p>
    
    <input id="demo" type="text">
    <button type="button" onclick="myFunction()">点我</button>
    
    <p id="p01"></p>
    
    <script>
    function myFunction() {
      var message, x;
      message = document.getElementById("p01");
      message.innerHTML = "";
      x = document.getElementById("demo").value;
      try { 
        if(x == "") throw "值是空的";
        if(isNaN(x)) throw "值不是一个数字";
        x = Number(x);
        if(x > 10) throw "太大";
        if(x < 5) throw "太小";
      }
      catch(err) {
        message.innerHTML = "错误: " + err + ".";
      }
      finally {
        document.getElementById("demo").value = "";
      }
    }
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <p>请输出一个 5 到 10 之间的数字:</p>
    
    <input id="demo" type="text">
    <button type="button" onclick="myFunction()">测试输入</button>
    <p id="message"></p>
    
    <script>
    function myFunction() {
        var message, x;
        message = document.getElementById("message");
        message.innerHTML = "";
        x = document.getElementById("demo").value;
        try { 
            if(x == "")  throw "值为空";
            if(isNaN(x)) throw "不是数字";
            x = Number(x);
            if(x < 5)    throw "太小";
            if(x > 10)   throw "太大";
        }
        catch(err) {
            message.innerHTML = "错误: " + err;
        }
    }
    </script>
    
    </body>
    </html>

  • 相关阅读:
    CentOS搭建nginx环境
    Gitment评论插件的使用
    GitPages部署自己的网站
    ubuntu防火墙规则之ufw
    鸟哥的Linux私房菜笔记第六章(二)
    一次使用InfluxDB数据库的总结
    网站实现markdown功能
    鸟哥的Linux私房菜笔记第六章(一)
    Flutter学习笔记(21)--TextField文本框组件和Card卡片组件
    Flutter学习笔记(20)--FloatingActionButton、PopupMenuButton、SimpleDialog、AlertDialog、SnackBar
  • 原文地址:https://www.cnblogs.com/tszr/p/10942709.html
Copyright © 2020-2023  润新知