简体   繁体   English

验证不适用于Firefox,但适用于IE,Chrome

[英]validation not working in Firefox but works in IE,Chrome

I use the following java script function for integer validate which means the text box can allow to enter only the integer values alone. 我将以下Java脚本函数用于整数验证,这意味着文本框仅允许输入整数值。 * It was work fine in Internet explorer and google chrome * .But I use this same function in FireFox the text box didn't allow to enter any characters in that which means it doesn't allow characters,numbers,space,anything else..How to solve this problem? * 在Internet Explorer和google chrome中都可以正常工作 。但是我在FireFox中使用了相同的功能,因此文本框中不允许输入任何字符,这意味着它不允许使用字符,数字,空格或其他任何内容。 。如何解决这个问题呢?

javascript function javascript功能

$('.intValidate').live('keypress', function(event) {
                var integervalidate = intValidate(event);
                if (integervalidate == false)
                    return false;
            });

function intValidate(event) {
    if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||(event.keyCode == 65 && event.ctrlKey === true) ||(event.keyCode >= 35 && event.keyCode <= 39))
        {
            return;
        }
    else 
    {
        if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 ))
        {
            event.preventDefault(); 
        }   

I use the class like , 我使用像这样的课程

  <input type="text" id="abcd" style="width:30px" maxlength="2"class="intValidate""/>

Your problem is the inconsistent way that browsers use the keypress event. 您的问题是浏览器使用keypress事件的方式不一致。 Read this post to get a good explanation with an example of a work around. 阅读这篇文章,以一个变通的示例获得很好的解释。

You're examining keycodes in the keypress event. 您正在检查keypress事件中的keypress代码。 You should be looking at charCode values instead. 您应该改为查看charCode值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 选项卡式内容在Chrome和Firefox中不起作用,但在IE中可用 - tabbed content not working in Chrome and Firefox but works in IE JavaScript函数不适用于Chrome和IE,但适用于FireFox - JavaScript function not working on Chrome & IE but works on FireFox JavaScript无法在IE和Firefox中运行,在Chrome中运行良好 - JavaScript not working in IE and Firefox, works fine in Chrome JavaScript 在 Firefox、Chrome 中不起作用 - 在 IE、Edge 中有效 - JavaScript not working in Firefox, Chrome - works in IE, Edge Onbeforeunload无法在Chrome / Firefox上运行,但可以在IE中运行 - Onbeforeunload not working on Chrome/Firefox but works in IE [0].submit 不适用于 IE 和 Firefox,在 Chrome 中完美运行 - [0].submit not working in IE and Firefox, works perfect in Chrome Javascript代码在Chrome和firefox中不起作用,但在IE中起作用 - Javascript Code is not working in Chrome and firefox but works in IE JS在Firefox中无法使用,在IE和Chrome中可以使用 - JS not working in Firefox, works in IE and Chrome JavaScript无法在IE和Chrome上运行?(在Firefox上运行) - Javascript not working on IE and Chrome?(it works on firefox) JavaScript表单验证适用于Chrome / Firefox,而不适用于IE / Edge - JavaScript Form Validation works in Chrome/Firefox not IE/Edge
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM