如何在C#中键入陷阱?
我只是一个编程新手。我想知道如何在文本框中键入字母或数字。例如,有一个关于年龄的文本框,用户不会在该文本框中键入字母。另外,我想知道如何限制在文本框中输入的字符数。例如,有一个关于等级的文本框,用户不能在等级上键入1111。我正在使用c#、asp.net和SQLServer2008作为数据库。一个例子对我来说就足够了。谢谢这里只输入数字:如何在C#中键入陷阱?,c#,asp.net,sql-server-2008,C#,Asp.net,Sql Server 2008,我只是一个编程新手。我想知道如何在文本框中键入字母或数字。例如,有一个关于年龄的文本框,用户不会在该文本框中键入字母。另外,我想知道如何限制在文本框中输入的字符数。例如,有一个关于等级的文本框,用户不能在等级上键入1111。我正在使用c#、asp.net和SQLServer2008作为数据库。一个例子对我来说就足够了。谢谢这里只输入数字: <style> #errmsg { color: red; } </style> <sc
<style>
#errmsg
{
color: red;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
//called when key is pressed in textbox
$("#quantity").keypress(function (e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
//display error message
$("#errmsg").html("Digits Only").show().fadeOut("slow");
return false;
}
});
});
</script>
Number : <input type="text" name="quantity" id="quantity" /> <span id="errmsg"></span>
#嗯
{
颜色:红色;
}
$(文档).ready(函数(){
//在文本框中按下键时调用
$(“#数量”)。按键(功能(e){
//如果字母不是数字,则显示错误,不键入任何内容
如果(e.which!=8&&e.which!=0&&e.which<48 | e.which>57)){
//显示错误消息
$(“#errmsg”).html(“仅限数字”).show().fadeOut(“慢”);
返回false;
}
});
});
编号:
此处仅输入数字:
<style>
#errmsg
{
color: red;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
//called when key is pressed in textbox
$("#quantity").keypress(function (e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
//display error message
$("#errmsg").html("Digits Only").show().fadeOut("slow");
return false;
}
});
});
</script>
Number : <input type="text" name="quantity" id="quantity" /> <span id="errmsg"></span>
#嗯
{
颜色:红色;
}
$(文档).ready(函数(){
//在文本框中按下键时调用
$(“#数量”)。按键(功能(e){
//如果字母不是数字,则显示错误,不键入任何内容
如果(e.which!=8&&e.which!=0&&e.which<48 | e.which>57)){
//显示错误消息
$(“#errmsg”).html(“仅限数字”).show().fadeOut(“慢”);
返回false;
}
});
});
编号:
最好的方法是使用javascript或jquery函数。例如,onkeypress事件将检查每个输入的符号,如果不是数字,它将删除它并向用户显示通知user@Khazratbek在哪里可以找到onkeypress事件?google:w3c输入编号查找“输入类型:编号”最好的方法是使用javascript或jquery函数。例如,onkeypress事件将检查每个输入的符号,如果它不是数字,它将删除它并向用户显示通知user@Khazratbek在哪里可以找到onkeypress事件?google:w3c输入编号查找“输入类型:编号”