On Key Down Restrict the user to enter Some Special Characters(On Key Down 限制用户输入一些特殊字符)
问题描述
我想限制用户在工具栏搜索中,不允许他/她使用一些特殊字符,例如 ('/','>','<','|').请帮帮我.
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;
}
});
我在搜索功能之前放置了这段代码.但这不起作用
I have placed this piece of code after before search function. But this does not work
推荐答案
如果你希望只允许在搜索工具栏的输入字段中输入一些特殊字符,你可以使用 dataEvents 的 searchoptions
使用 type:'keypress'
定义code> 或 type:'keydown'
.随后会为相应的输入字段调用 jQuery.bind
和 jQuery.unbind
.只允许数字的代码片段如下
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;
}
}
}
]
}
在现场 demo 你将不能在姓名"的搜索字段中输入数字.
这篇关于On Key Down 限制用户输入一些特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:On Key Down 限制用户输入一些特殊字符


基础教程推荐
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 将数据集转换为列表 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 如果条件可以为空 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 从 C# 控制相机设备 2022-01-01