zoukankan      html  css  js  c++  java
  • parseint和isNaN用法

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    </head>
    
    <body>
    <script>
        var a='12';
        alert(parseInt(a)+1);//字符串转数字
    </script>
    </body>
    </html>
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    </head>
    
    <body>
    <input type="text" id="txt1" />
    <br/>
    <br/>
    <input type="text" id="txt2" />
    <br/>
    <br/>
    <input type="button" id="btn" value="点击" />
    <script>
        var otxt1=document.getElementById('txt1');
        var otxt2=document.getElementById('txt2');
        var obtn=document.getElementById('btn');
        obtn.onclick=function()
        {
            var n1=parseInt(otxt1.value);
            var n2=parseInt(otxt2.value);
            alert(n1+n2)
        }
    </script>
    </body>
    </html>
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    </head>
    
    <body>
    <input type="text" id="txt1" />
    <br/>
    <br/>
    <input type="text" id="txt2" />
    <br/>
    <br/>
    <input type="button" id="btn" value="点击" />
    <script>
        var otxt1=document.getElementById('txt1');
        var otxt2=document.getElementById('txt2');
        var obtn=document.getElementById('btn');
        obtn.onclick=function()
        {    
            var n1=parseInt(otxt1.value);
            var n2=parseInt(otxt2.value);
            
            if(isNaN(n1))
                {
                    alert('你输入的第一个数字有误!');
                }
            else if(isNaN(n2))
                {
                    alert('你输入的第二个数字有误!');
                }
            else
            {
                alert(n1+n2);
            }
        }
    </script>
    </body>
    </html>
  • 相关阅读:
    NYOJ--703
    CDOJ--1369
    NYOJ--205
    NYOJ--520
    NYOJ--69
    CDOJ--1237
    [gist]Android SHA-1
    ConnectionAbortedError: [WinError 10053] 你的主机中的软件中止了一个已建立的连接
    SyntaxError:unexpected EOF while parsing(<string,line 0>)
    Django之get请求url的参数
  • 原文地址:https://www.cnblogs.com/xinlvtian/p/8322153.html
Copyright © 2011-2022 走看看