• 6.2文本框数字求和


    功能:在文本框中输入任意数字点按钮都能求和,输错点击会提醒错误

    事件:onclick

    属性:input中的value

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Examples</title>
    <meta name="description" content="">
    <meta name="keywords" content="">

    <link href="css1.css" rel="stylesheet" type="text/css"
    charset="UTF-8">
    </head>
    <body>
    <input id="txt1" type="text"/ >
    <input id="txt2" type="text"/ >
    <input id="btn" type="button" value="数字求和"/ >
    <script src="js1.js"> </script>
    </body>
    </html>

    ////////////////////js

    window.onload=function(){
    var oBtn=document.getElementById("btn");
    oBtn.onclick=function(){
    var oTxt1=document.getElementById("txt1");
    var oTxt2=document.getElementById("txt2");
    var n1=oTxt1.value;
    var n2=oTxt2.value;
    if(isNaN(n1)==true){
    alert("您输入的第一个数字有误");
    }
    else if(isNaN(n2)==true){
    alert("您输入的第二个数字有误");
    }

    else{
    alert(parseInt(n1)+parseInt(n2));
    }

    };
    };

  • 相关阅读:
    Delphi中WebBbrowser的编程 转
    博客园设置目录
    iTerm
    python
    谷歌浏览器插件的导出导入
    Chapter10 属性
    WPF之Binding
    ASP.NET 路由系统
    Silverlight中使用Application.GetResourceStream方法加载资源时得到的总是null
    基于IoC的ControllerFactory
  • 原文地址:https://www.cnblogs.com/luxiaoli/p/8509288.html
Copyright © 2020-2023  润新知