您的位置:首页 > 其它

如何在一个人输入框中只输入数字

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.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>

然后你就可以看到结果了,

小小的简单例子,希望大家,喜欢
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: