1. <tfoot id='115gR'></tfoot>
      <i id='115gR'><tr id='115gR'><dt id='115gR'><q id='115gR'><span id='115gR'><b id='115gR'><form id='115gR'><ins id='115gR'></ins><ul id='115gR'></ul><sub id='115gR'></sub></form><legend id='115gR'></legend><bdo id='115gR'><pre id='115gR'><center id='115gR'></center></pre></bdo></b><th id='115gR'></th></span></q></dt></tr></i><div id='115gR'><tfoot id='115gR'></tfoot><dl id='115gR'><fieldset id='115gR'></fieldset></dl></div>
    1. <small id='115gR'></small><noframes id='115gR'>

        <bdo id='115gR'></bdo><ul id='115gR'></ul>
      <legend id='115gR'><style id='115gR'><dir id='115gR'><q id='115gR'></q></dir></style></legend>

      HTML 输入类型=“数字";从 javascript 访问时仍

      时间:2023-10-12
      <tfoot id='ghyCB'></tfoot>
      1. <legend id='ghyCB'><style id='ghyCB'><dir id='ghyCB'><q id='ghyCB'></q></dir></style></legend>
      2. <small id='ghyCB'></small><noframes id='ghyCB'>

          <tbody id='ghyCB'></tbody>

            <i id='ghyCB'><tr id='ghyCB'><dt id='ghyCB'><q id='ghyCB'><span id='ghyCB'><b id='ghyCB'><form id='ghyCB'><ins id='ghyCB'></ins><ul id='ghyCB'></ul><sub id='ghyCB'></sub></form><legend id='ghyCB'></legend><bdo id='ghyCB'><pre id='ghyCB'><center id='ghyCB'></center></pre></bdo></b><th id='ghyCB'></th></span></q></dt></tr></i><div id='ghyCB'><tfoot id='ghyCB'></tfoot><dl id='ghyCB'><fieldset id='ghyCB'></fieldset></dl></div>

                <bdo id='ghyCB'></bdo><ul id='ghyCB'></ul>
              • 本文介绍了HTML 输入类型=“数字";从 javascript 访问时仍然返回一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我是 javascript 新手,我正在尝试学习 JS 中的函数等,并尝试添加 2 个数字

                I'm new to javascript , I'm trying learning how functions etc in JS and trying to add 2 numbers

                <!DOCTYPE html>
                <html lang="en">
                
                <head>
                  <meta charset="UTF-8">
                  <title>JS ADD</title>
                </head>
                
                <body>
                
                  <h1>Funcitons is JS</h1>
                
                
                  <input type="number" id="num1">
                  <input type="number" id="num2">
                
                  <button type="button" onclick="addNumAction()">
                    Add
                  </button>
                
                  <script>
                    function addNum(n1, n2) {
                      return parseInt(n1) + parseInt(n2);
                    }
                
                    function addNumAction() {
                      var n1 = document.getElementById("num1").value;
                      var n2 = document.getElementById("num2").value;
                
                      var sum = addNum(n1, n2);
                      window.alert("" + sum);
                
                    }
                  </script>
                
                </body>
                
                </html>

                如果我删除 parseInt() 值仅被视为字符串,那么使用 <input type="number"> 有什么意义?请向我解释.使用什么字段来获取数字输入?

                If I remove the parseInt() the value is treated as a string only , then what is the point of using <input type="number"> ?please explain to me. what field to use for getting input as a number?

                推荐答案

                得到一个字符串是正常的.

                It's normal you get a string.

                数字类型的目的是移动浏览器使用它来显示正确的键盘,一些浏览器使用它来进行验证.例如,email 类型将显示带有 @ 和 '.' 的键盘.在键盘上,number 将显示一个数字键盘.

                The purpose of the number type is that mobile browsers use this for showing the right keyboards and some browsers use this for validation purposes. For example the email type will show a keyboard with the @ and '.' on the keyboard and number will show a numeric keyboard.

                这篇关于HTML 输入类型=“数字";从 javascript 访问时仍然返回一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在 html 正文中显示 javascript var 下一篇:将阿拉伯文本转换为 HTML 代码字符

                相关文章

                最新文章

                <legend id='GrHRJ'><style id='GrHRJ'><dir id='GrHRJ'><q id='GrHRJ'></q></dir></style></legend>

                1. <i id='GrHRJ'><tr id='GrHRJ'><dt id='GrHRJ'><q id='GrHRJ'><span id='GrHRJ'><b id='GrHRJ'><form id='GrHRJ'><ins id='GrHRJ'></ins><ul id='GrHRJ'></ul><sub id='GrHRJ'></sub></form><legend id='GrHRJ'></legend><bdo id='GrHRJ'><pre id='GrHRJ'><center id='GrHRJ'></center></pre></bdo></b><th id='GrHRJ'></th></span></q></dt></tr></i><div id='GrHRJ'><tfoot id='GrHRJ'></tfoot><dl id='GrHRJ'><fieldset id='GrHRJ'></fieldset></dl></div>

                  <small id='GrHRJ'></small><noframes id='GrHRJ'>

                  <tfoot id='GrHRJ'></tfoot>
                    <bdo id='GrHRJ'></bdo><ul id='GrHRJ'></ul>