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 限制用户输入一些特殊字符
基础教程推荐
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
