Jquery onKeyPress事件 [英] Jquery onKeyPress Event
本文介绍了Jquery onKeyPress事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi Team
i想要执行验证OnkeyPress JQuery Event。
我想对字母表进行验证,删除,退格,向左箭头,向上箭头,向右箭头,并在一个文本框中使用JavascriptkeyCode向下箭头..如何做到这一点? ..kindly帮助..
我试过这个
Hi Team
i want to perform a validations OnkeyPress JQuery Event.
I want to do validation for Alphabets,delete,backspace ,left arrow,up arrow,right arrow,and down arrow using JavascriptkeyCode in one Textbox..How to do this? ..kindly Help..
I have tried this
function keyPressFunctionForValidations(e) {<br />
debugger;<br />
var code = e.keyCode || e.which;<br />
if (code != 32 (code <65 || code > 90)) {<br />
return<br />
}<br />
}
谢谢
Harshal Raut
Thanks
Harshal Raut
推荐答案
试试这个..
try this..
<script type="text/javascript">
( function (){
(' #txt')。keypress( function (e){
var charCode = e.keyCode || e.which;
if (charCode == 37 || charCode == 39 ) returntrue ; // 允许箭头
if (charCode == 46 ) return true ; // delete
if (charCode == 190 || charCode == 110 )返回 true ; // 句号或点
如果(charCode == 35 || charCode == 36 )返回 true ; // home,end
if (charCode == 8 || charCode == 9 )返回 true ; // 退格,标签
如果(charCode> 64 && charCode< 91 ) return true ; // a - z
if (charCode> 96 && charCode< 123 ) return true ; // A-Z
e.preventDefault();
});
});
< / script>
('#txt').keypress(function (e) { var charCode = e.keyCode || e.which; if (charCode == 37 || charCode == 39) return true; // allow arrows if (charCode == 46) return true; //delete if (charCode == 190 || charCode == 110) return true; // period or dot if (charCode == 35 || charCode == 36) return true; // home, end if (charCode == 8 || charCode == 9) return true; // backspace , tab if (charCode > 64 && charCode < 91) return true; // a - z if (charCode > 96 && charCode < 123) return true; // A- Z e.preventDefault(); }); }); </script>
这篇关于Jquery onKeyPress事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文