.net 问题 ( 积分: 50 )

S

syhqll

Unregistered / Unconfirmed
GUEST, unregistred user!
有个问题!用一个TEXTBOX 在输入的时候如何让他只能输入数字不能有字母?
 
有个问题!用一个TEXTBOX 在输入的时候如何让他只能输入数字不能有字母?
 
在客户端处理文本框的onkeypress事件
给你个例子
<%@ Page language=&quot;c#&quot;
AutoEventWireup=&quot;false&quot;
codePage=&quot;936&quot;%>
<HTML>
<HEAD>
<script>
functiondo
keypress()
{
var c=String.fromCharCode(event.keyCode);
if(c<'0' || c>'9')
event.keyCode=0;
}
</script>
</HEAD>
<body>
<form id=&quot;Form1&quot;
method=&quot;post&quot;
runat=&quot;server&quot;>
<asp:TextBox id=&quot;TextBox1&quot;
runat=&quot;server&quot;
onkeypress=&quot;dokeypress()&quot;></asp:TextBox>
</form>
</body>
</HTML>
 
顶部