我使用下面的代码..但在下面的代码没有在Internetexplorer执行....当我输入字符我有一个​​警报消息但添加字符..Plz一次检查。 [英] Im Useing Below Code..But In The Below Code Was Not Execute In Internetexplorer....When I Enter Characters I Got A Alert Message But Add The Character..Plz Once Check.

查看:64
本文介绍了我使用下面的代码..但在下面的代码没有在Internetexplorer执行....当我输入字符我有一个​​警报消息但添加字符..Plz一次检查。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type="text/javascript">
   function CheckNumeric(e) {

       if (window.event) // IE
       {
           if ((e.keyCode < 48 || e.keyCode > 57) & e.keyCode != 8) {
               event.returnValue = false;
               alert('Please Enter Numbers');
               return false;

           }
       }
       else { // Fire Fox
           if ((e.which < 48 || e.which > 57) & e.which != 8) {
               e.preventDefault();
               alert('Please Enter Numbers');
               return false;

           }
       }
   }

推荐答案

只需将return添加到在onkeypress调用方法,它适用于所有浏览器。



Just add "return" to the calling method at onkeypress and it will work on all browsers.

<input type="text" value="" onkeypress="return CheckNumeric(event);" />


参考 - 仅允许使用JavaScript的TextBox中的数值(数字) [ ^ ]。


这篇关于我使用下面的代码..但在下面的代码没有在Internetexplorer执行....当我输入字符我有一个​​警报消息但添加字符..Plz一次检查。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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