数字判断和文本框提交事件,WEB SERVICE等

代码

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title></title>
    
<script language ="javascript" type="text/javascript" >
        var numeric 
= /^[0-9]{1,8}$/;   //验证数字的正则表达式,后面表示长度限制
        function txtPrimeChange() 
        {
            var key 
= event.keyCode;
            var KEYENTER 
= 13;            
            
//alert(key);
            
//var char=String.fromCharCode(key); //得到键盘输入的字符

            
if (key == KEYENTER) {
                
if (!numeric.test(document.all.txtPrime.value)) {
                    alert(
"请输入数字");
                    document.all.txtPrime.value 
= "";
                }
                
else {
                    document.all.btnSubmit.click();
                    
//document.all.txtPrime.focus();
                }
                document.all.txtPrime.focus();
            }
        }
        
        
//要使TXT的onkeydown事件生效,必须屏蔽FORM的KEYDOWN事件
        function frmKeyDown() {
            
if (event.keyCode == 13)
                
return false;
        }
        function pageLoad() {
            document.all.txtPrime.value 
= "";
            document.all.txtPrime.focus();
        }    
        function btnSubmitOnClient() {
            
if (!numeric.test(document.all.txtPrime.value)) {
                alert(
"请输入数字");
                document.all.txtPrime.value 
= "";
                document.all.txtPrime.focus();
                
return false;
            }            
            
return true;
        }
    
</script>
</head>
<body onload="javascript:pageLoad()">
    
<form id="form1" runat="server">
    
<div>
    
        
<asp:Panel ID="Panel1" runat="server" onkeydown="return frmKeyDown()">
            
<asp:Label ID="Label1" runat="server" Text="请输入一个数:"></asp:Label>
            
<asp:TextBox ID="txtPrime" runat="server" onkeydown="txtPrimeChange()"></asp:TextBox>
            
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" OnClientClick="return btnSubmitOnClient();" Text="验证" />
            
<br />
            
<asp:Label ID="lblTestResult" runat="server"></asp:Label>
        
</asp:Panel>    
    
</div>    
    
</form>
</body>
</html>
WEB SERVICE的小例子
posted on 2010-12-27 23:59  ringwang  阅读(193)  评论(0编辑  收藏  举报