Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 输入实时html中的最大值限制_Java_Html_Validation - Fatal编程技术网

Java 输入实时html中的最大值限制

Java 输入实时html中的最大值限制,java,html,validation,Java,Html,Validation,我需要限制name=“name”字段中的最大输入值。 实时处理。约束不起作用。 我该怎么做 <script> function showcost() { document.getElementById("cost").value = document.getElementById('serviceslist').value; } function sum2() { var x = doc

我需要限制name=“name”字段中的最大输入值。 实时处理。
约束不起作用。 我该怎么做

 <script>
        function showcost() {
            document.getElementById("cost").value = document.getElementById('serviceslist').value;
        }
        function sum2() {
            var x = document.getElementById('cost2').value;
            var y = document.getElementById('amount2').value;
            var total = (parseFloat(x) * parseFloat(y))/100;
            document.getElementById("total2").value = total;
        }
    </script>

    <br>
<div class="container">
    <div class="row">
        <div class="col-md-12 col-md-offset-0">

    <form>

        <p>Procent:<input name="name" size="3" min=1 max=100 type="number" id="amount2"  step=1 id="cost2" pattern="[0-9]" onchange="sum2()" oninput="this.value = this.value.replace(/[^0-9]/g, '').replace(/(\..*)\./g, '$1');" );" ></p>
        <p>Результат:<input type="text" id="total2" value="0" disabled></p>
    </form>
        </div>
    </div>
</div>

函数showcost(){
document.getElementById(“成本”).value=document.getElementById(“服务列表”).value;
}
函数sum2(){
var x=document.getElementById('cost2')。值;
var y=document.getElementById('amount2')。值;
var total=(parseFloat(x)*parseFloat(y))/100;
document.getElementById(“total2”).value=total;
}


Procent:您是想使用
javascript
标记而不是
java
标记吗?这个约束似乎对我很有效,如果我键入的值超过100,框周围会出现一个红色边框,表示错误。通过“实时处理”,您特别想要什么