首页 技术 正文
技术 2022年11月15日
0 收藏 851 点赞 4,261 浏览 1773 个字
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="../Scripts/jquery-1.10.2.js"></script>
<style type="text/css">
body {
font-size: 9pt;
font-family: Arial;
}
</style>
<script type="text/javascript">
var specialKeys = new Array();
specialKeys.push(); //Backspace
function IsNumeric(e) {
var keyCode = e.which ? e.which : e.keyCode
var ret = ((keyCode >= && keyCode <= ) || specialKeys.indexOf(keyCode) != -);
document.getElementById("error").style.display = ret ? "none" : "inline";
return ret; } $(document).ready(function () { // Setting focus on first textbox $('input:text:first').focus(); // binding keydown event to textbox $('input:text').bind('keydown', function (e) { // detecting keycode returned from keydown and comparing if its equal to 13 (enter key code) if (e.keyCode == ) { // by default if you hit enter key while on textbox so below code will prevent that default behaviour e.preventDefault(); // getting next index by getting current index and incrementing it by 1 to go to next textbox var nextIndex = $('input:text').index(this) + ; // getting total number of textboxes on the page to detect how far we need to go var maxIndex = $('input:text').length; // check to see if next index is still smaller then max index if (nextIndex < maxIndex) { // setting index to next textbox using CSS3 selector of nth child $('input:text:eq(' + nextIndex + ')').focus(); }
} }); });
</script></head><body>
Numeric Value:
<input type="text" id="text1" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" />
<input type="text" id="text2" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" />
<input type="text" id="text3" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" />
<span id="error" style="color: Red; display: none">* Input digits ( - )</span>
</body></html>

More information:

http://www.aspsnippets.com/Articles/Allow-only-numeric-value-numbers-in-TextBox-using-JavaScript.aspx

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919