按下按键时限制用户输入一些特殊字符 [英] On Key Down Restrict the user to enter Some Special Characters

查看:152
本文介绍了按下按键时限制用户输入一些特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过不允许他/使用一些特殊字符,如('/','>','<','|').Please帮我出她来限制工具栏搜索用户。

I want to restrict the user in toolbar search by not allowing him/her using Some Special Characters like ('/','>','<','|').Please help me out.

$("#tblFundComp").bind("keydown",function(e) 
{
  if(e.keyCode >=48 && e.keyCode <=57 ) 
  { 
    return false; 
  }
  else 
  { 
    return true; 
  }
}); 

我已经把这块code之前,搜索功能后。但是,这并不正常工作

I have placed this piece of code after before search function. But this does not work

推荐答案

如果您想只允许某些特殊字符在您可以使用搜索工具栏输入字段中输入的 dataEvents searchoptions 中定义使用<$ C $的C>键入:'键preSS 或键入:的keydown。它将如下调用 jQuery.bind jQuery.unbind 为对应的输入字段。其中的code片段只允许数字是继

If you want allow only some special characters are entered in the input field of the search toolbar you can use dataEvents of the searchoptions defined using type:'keypress' or type:'keydown'. It will follows to call jQuery.bind and jQuery.unbind for the corresponding input field. The code fragment which allows only digits is following

searchoptions: {
    dataEvents: [
        {
            type: 'keypress', // keydown
            fn: function(e) {
                // console.log('keypress');
                if(e.keyCode >=48 && e.keyCode <=57) {
                    // allow digits
                    return true;
                } else {
                    // disallow the key
                    return false;
                }
            }
        }
    ]
}

在现场演示你会无法输入数字在搜索领域的名称。

In the live demo you will be not able to enter digits in the search field for the 'Name'.

这篇关于按下按键时限制用户输入一些特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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