【问题标题】:Using <input type="text" for calculator input instead of <input type="number"使用 <input type="text" 代替 <input type="number" 进行计算器输入
【发布时间】:2016-10-07 11:19:17
【问题描述】:

以下是我正在创建的应用程序的一部分。 它实际上可以完美地工作,除了在一些显示没有减号键的数字键盘的特定 android 手机上。 Tmin 很可能总是一个负数。 如果我将所有输入转换为

<head>
<link rel="stylesheet" type="text/css">
    <script type="text/javascript"></script>
    <body>
        <body STYLE="background-color: #F87217; background-size: cover"></body>
        <br>
            <center>
                <h2 style="font-family:verdana;">Title</h2>
            </center>
            <center>
                <p>Voc + &#x194;v (Tmin - TSTC)M
                </
                <p>
                    <form onsubmit="return false" oninput="amount.value = (a.valueAsNumber + b.valueAsNumber * (d.valueAsNumber - c.valueAsNumber) * e.valueAsNumber) .toFixed(2)">
                        <label for="a">Voc Array</label>
                        <center>
                            <input type="number" step="0.01" min="0" id="a" name="a">
                            </center>
                            <label for="b">&#x194;v</label>
                            <center>
                                <input type="number" step="0.01" min="0" id="b" name="b">
                                </center>
                                <label for="c">Tmin</label>
                                <center>
                                    <input type="number" step="0.001" min="-5.00" id="c" name="c">
                                    </center>
                                    <label for="d">Tstc</label>
                                    <center>
                                        <input type="number" step="0.0001" min="0" id="d" name="d">
                                        </center>
                                        <label for="e">M</label>
                                        <center>
                                            <input type="number" step="0.001" min="0" id="e" name="e">
                                            </center>
                                            <p>
                                                <h3>Total: </h3>
                                                <strong>Volts 
                                                    <output name="amount" step="0.01" min="0" for="a b c d e">0</output>
                                                </strong>
                                            </p>
                                            <input type="reset" value="Reset">
                                            </form>
                                        </center>
                                    </link>

【问题讨论】:

标签: html input


【解决方案1】:

在提交按钮上发生 onclick' 或 'onsubmit' 或 'onblur' 事件时,调用 javascript 函数将它们转换为数值。

我建议你了解javascript。

 1) how read the value of the DOM element of your input field.
 2)How to remove/(or replace with null) the characters except numbers from variable.(learn about regular expression in string replace/remove)
 3) how to writes the value of variable to teh DOM element (Your's input field)

在提交表单之前执行此操作。

你可以参考How to make HTML input tag only accept numerical values?这个已经提出的问题

【讨论】:

    猜你喜欢
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 2014-02-08
    • 2013-06-28
    • 2018-09-13
    • 2013-04-19
    • 1970-01-01
    相关资源
    最近更新 更多