zoukankan      html  css  js  c++  java
  • js入门3-猜数字

    <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3c.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3x.org/1999/xhtml">
        <head>
            <title>Javascript Day01</title>
            <meta http-equlv="content-type" content="text/html;charset=utf-8"/>
            <script language="javascript" src="js_demo1.js" type="text/javascript"></script>
            <script language="javascript" type="text/javascript">
                function firstMethod(){
                    alert("Hello World in script block.");
                }
                </script>
            </head>
            <form>
                <h2>1.Hello Word</h2>
                <input type="button" value="first button" onclick="alert('Hello Word');"/>
                <input type="button" value="second button" onclick="firstMethod();"/>
                <input type="button" value="third button" onclick="secondMethod();"/>
                <h2>2.判断数据类型,并计算平方</h2>
                <input type="text" id="txtData"/><br/>
                <input type="button" value="计算平方" onclick="getSquare()";/>
                <h2>3.猜数字</h2>
                请录入猜测的数字(1-20之间的整数):<br/>
                <input id="txtNumber" type="text" onblur="guessNumber()";/>
            </form>
        </body>
    </html>
               

    js:

    function secondMethod(){
        alert("hello world");
    }
    function getSquare(){
        var str = document.getElementById("txtData").value;
        if(isNaN(str))
            alert("请录入数值");
        else{
            var data=parseFloat(str);
            var result = data* data;
            alert(result);
        }
    }
    //猜数字
    function guessNumber(){
        var result = 10;
        //得到用户的录入
        var str = document.getElementById("txtNumber").value;
        //比较
        if(isNaN(str))
            alert("请录入数值");
        else{
            var data = parseFloat(str);
            var info = data > result ?"大了":"小了";
            info = data == result ? "猜对了":info;
            alert(info);
        }
    }   

  • 相关阅读:
    sql server登录账户看不到sql server代理和维护计划
    Redis(1.19)redis内存消耗、redis内存优化
    【最佳实践】bat实现自动化运行sql
    Redis(1.18)redis阻塞分析
    某机场网络环境分析
    【js】setInterval是个坑!chrome定时截图保存实现
    【操作系统】CPU中的时间片的概念
    Jeff Atwood:软件工程已死?
    vscode配置 eslint+prettierrc自动格式化vue3、ts、tsx文件
    基于.NET的大型Web站点StackOverflow架构分析
  • 原文地址:https://www.cnblogs.com/ls00/p/6958537.html
Copyright © 2011-2022 走看看