zoukankan      html  css  js  c++  java
  • js入门2计算平方

    数据类型转换函数

    toString--转换成字符串;--所有数据类型均可转换成String类型

    parseInt--强制转换成整数;如果不能转换则返回NaN

    parseFloat--强制转换成浮点数,如果不能转换返回NaN

    <!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()";/>
            </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);
        }
    }

  • 相关阅读:
    Mysql:Group Replication & Replication
    使用winsw包装服务将nginx包装为Windows服务
    Nginx的一些常用配置
    在ASP.NET Core 2.0中使用Facebook进行身份验证
    展现层实现增删改查
    ABP创建应用服务
    ABP领域层定义仓储并实现
    ABP领域层创建实体
    通过模板创建一个ABP项目
    Android UI组件:布局管理器
  • 原文地址:https://www.cnblogs.com/ls00/p/6958233.html
Copyright © 2011-2022 走看看