应使用java脚本在文本框中允许0-59数字 [英] 0-59 number should allow in text box using java script

查看:145
本文介绍了应使用java脚本在文本框中允许0-59数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我希望用户在html文本框中输入0-59号码。如何使用javascript以及如何将相同的java脚本函数调用到相同的HTML文本框。





请立即回复我......请

推荐答案

嗨Kamal,



试试这段代码,

这是javascript

Hi Kamal,

Try this code,
Here is the javascript
<script type="text/javascript">
        function validateTextBox() {
            var obj = document.getElementById('txtBox');
            if (obj.value > -1 && obj.value < 60) {

                return true;

            }

            else {

                alert('Range should be in 0-59');

                return false;

            }

        }



    </script>



在html中你需要在onBlur事件中调用它,在失去焦点时会抛出错误。

当你想抛出警告时你可以改变(onKeypress,onKeydown或者什么)取决于你。

HTML代码:


And in html you need to call it in onBlur event, on losing its focus it will throw error.
You can change(onKeypress,onKeydown or something) when you want to throw the alert that depends on you.
HTML code:

<input type="text" id="txtBox" onblur="validateTextBox()"/>





我希望这会对你有所帮助。



问候,

RK



I hope this helps you a bit.

Regards,
RK


var obj=document.getElementbyid('txtbox1');
if(obj.value >-1 && obj.value< 60)
{
return true;
}
else
{
return false
alert('enter b/w 0-59 only');
}


这篇关于应使用java脚本在文本框中允许0-59数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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