检查输入长度不大于10 [英] check input length not more than 10

查看:149
本文介绍了检查输入长度不大于10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 函数checkNumbers(输入) )
{
if(document.getElementById(answer)。value.length == 10)
{
input.value = input.value.replace(input.value ,'');
}
}

< input type =textmaxlength =10onkeyup =checkNumbers(isAllowedSymbol(this)); checkNumbers(this);placeholder = Enter dataname =answer>< br>


解决方案

在你的html中使用 name ,在你的js中你正在查找 id



更改 name ='answer' id ='answer' / p>

或者在您的JS中尝试:



document.getElementsByName('answer') [0] .value == 10


Trying to check my value length and make it only to 10 numers.What is my problem?

 function checkNumbers(input)
    {   
     if (document.getElementById("answer").value.length == 10)
        {
        input.value = input.value.replace(input.value, '');
        } 
    }

    <input type="text" maxlength="10" onkeyup="checkNumbers(isAllowedSymbol(this));checkNumbers(this); "placeholder="Enter data" name="answer" " > <br>

解决方案

In your html your using name and in your js you are lookng for id

change name='answer' to id='answer'

Or alternatively in your JS try:

document.getElementsByName('answer')[0].value==10

这篇关于检查输入长度不大于10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆