如何在一个人输入框中只输入数字
2014-12-20 12:09
169 查看
好久没写博客了,看到一篇博文讲如何在一个textbox中只能写数字的用js的
下面具体讲讲怎么实现,首先在web中新建一个空的web程序
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication6.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
function ValidNumeric() {
var charCode = (event.which) ? event.which : event.keyCode;
if (charCode > 47 && charCode < 58)
{
return true;
} else {
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
LoginID<asp:TextBox ID="LoginID" runat="server" onkeypress="return ValidNumeric() "></asp:TextBox>
</form>
</body>
</html>
然后你就可以看到结果了,
小小的简单例子,希望大家,喜欢
下面具体讲讲怎么实现,首先在web中新建一个空的web程序
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication6.WebForm1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script type="text/javascript"> function ValidNumeric() { var charCode = event.whitch ? event.which : event.keyCode; if (charCode > 47 && charCode < 58) { return true; } else { return false; } } </script> </head> <body> <form id="form1" runat="server"> <div> </div> LoginID<asp:TextBox ID="LoginID" runat="server" onkeypress="return ValidNumeric() "></asp:TextBox> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication6.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
function ValidNumeric() {
var charCode = (event.which) ? event.which : event.keyCode;
if (charCode > 47 && charCode < 58)
{
return true;
} else {
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
LoginID<asp:TextBox ID="LoginID" runat="server" onkeypress="return ValidNumeric() "></asp:TextBox>
</form>
</body>
</html>
然后你就可以看到结果了,
小小的简单例子,希望大家,喜欢
相关文章推荐
- html中input输入框如何限定输入数字或英文
- 如何使输入框input只能输入数字
- 如何让textField输入框 限制输入字数的同时,还只让输入数字和字母
- 如何用JavaScript,jQuery,Zepto来实现输入框只能输入纯数字
- 如何过滤让输入框 只输入字母和数字
- 如何让textField输入框 限制输入字数的同时,还只让输入数字和字母
- Delphi 中的Edit输入框如何限定只能输入七位数,,第一位为1到4的数字,第二位到第七位为日期格式取后六位,如:20060123取:060123,任何一位都
- 如何让textField输入框 限制输入字数的同时,还只让输入数字和字母
- 如何使文本框中输入的必须是数字?
- 如何控制在DataGrid中不能输入全角数字,符号,字母?
- 让文本输入框只能输入数字
- C# winform 程序中如何限制一个文本框中只输入数字和字母(撤消键可以用)
- 如何是SELECTION屏幕输入框变成密码输入框
- 如何控制文本框只能输入某个范围内的数字,如:0到60之间?
- 只让输入数字的输入框
- 只让输入数字的输入框
- 如何是SELECTION屏幕输入框变成密码输入框
- js如何判断输入是否为正整数、浮点数等数字的函数
- 如何限制文本框只能输入数字,小数点,英文,汉字等各类代码
- 让文本输入框只能输入数字