这个Javascript代码在mozilla firefox中不起作用?请帮我 [英] This Javascript code not working in mozilla firefox? please help me

查看:57
本文介绍了这个Javascript代码在mozilla firefox中不起作用?请帮我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function numericValidation(txtvalue) {

            var e = event || evt; // for trans-browser compatibility
            var charCode = e.which || e.keyCode;
            if (!(document.getElementById(txtvalue.id).value)) {
                if (charCode > 31 && (charCode < 48 || charCode > 57))
                    return false;
                return true;
            }
            else {
                var val = document.getElementById(txtvalue.id).value;
                if (charCode == 46 || (charCode > 31 && (charCode > 47 && charCode < 58))) {
                    var points = 0;
                    points = val.indexOf(".", points);
                    if (points >= 1 && charCode == 46) {
                        return false;
                    }
                    if (points >= 1) {
                        var lastdigits = val.substring(val.indexOf(".") + 1, val.length);
                        if (lastdigits.length >= 2) {
                            alert("Two decimal places only allowed");
                            return false;
                        }
                    }
                    return true;
                }
                else {
                    alert("Only Numarics allowed");
                    return false;
                }
            }
        }

推荐答案

对于数字验证,您可以轻松使用 jQuery数字验证插件。它已经过测试,适用于所有浏览器。



查看:



http://www.texotela.co.uk/code/jquery/numeric/ [< a href =http://www.texotela.co.uk/code/jquery/numeric/target =_ blanktitle =New Window> ^ ]



示例:



For numeric validation you can easily use jQuery Numeric validation plugin.It has been tested for all browsers.

Check this :

http://www.texotela.co.uk/code/jquery/numeric/[^]

Example:


(文件).ready(function(){
(document).ready(function(){


(。numeric)。numeric();
});
(".numeric").numeric(); });





更多信息:



http://stackoverflow.com/questions/891696/jquery-what-is-the-best-way-到限制-数仅输入换文本框,所有 [ ^ ]



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



More info :

http://stackoverflow.com/questions/891696/jquery-what-is-the-best-way-to-restrict-number-only-input-for-textboxes-all[^]

I hope this will help to you.


这篇关于这个Javascript代码在mozilla firefox中不起作用?请帮我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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