我使用这段代码来验证下划线。但是它不适用于下划线(keyCode =95)。但要为其他关键密码工作。如何验证下划线??我想避免输入下划线。
function ValidateUnderscore(e) {
if (e.keyCode == 95)
return false;
else
return true;
}
发布于 2014-03-29 22:05:39
如您所见:http://jsfiddle.net/kNHe6/
下划线(和减号)的键码为189。所以,把你的支票改为189而不是95
假设您想要有减号的可能性,请考虑如下所示:http://jsfiddle.net/U32C9/1/
$(document).ready(function(){
$("#text").keypress(function(e) {
if(String.fromCharCode(e.which) == '_')
e.preventDefault();
});
});
https://stackoverflow.com/questions/22740698
复制相似问题