仅接受数字的TextBox! [英] TextBox which accepts only numbers!
本文介绍了仅接受数字的TextBox!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是使用ASP.Net创建的顾问注册页面],当我们在文本框中输入不接受的任何字符时.文本框中仅接受数字!(仅数字值)!
I was created consultant registration page using ASP.Net], When we enter any characters in text box that will not accept.. Text Box which accepts only numbers!(numeric values only)!!
推荐答案
阅读这些内容:
http://forums.asp.net/t/1192407.aspx/1 [ ^ ]
仅接受数字的文本框 [
Read these :
http://forums.asp.net/t/1192407.aspx/1[^]
TextBox which accepts only numbers[^]
try:
try:
<BODY>
<script language="JavaScript">
function onlyNumbers(evt)
{
var e = event || evt; // for trans-browser compatibility
var charCode = e.which || e.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
</script>
<input type="text" onkeypress="return onlyNumbers();">
</BODY>
将以下javascript添加到页面的HEAD区域:
Add the following javascript to the HEAD area of your page:
<SCRIPT language=Javascript>
<!--
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
//-->
</SCRIPT>
然后,在文本框定义中添加onkeypress
:
Then, add onkeypress
to your textbox definition:
<asp:TextBox ID="TextBox1" runat="server" onkeypress="return isNumberKey(event)"></asp:TextBox>
这篇关于仅接受数字的TextBox!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文