• 数字判断和文本框提交事件,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的小例子
  • 相关阅读:
    【2018.05.05 C与C++基础】C++中的自动废料收集:概念与问题引入
    【2018.04.27 C与C++基础】关于switch-case及if-else的效率问题
    【2018.04.19 ROS机器人操作系统】机器人控制:运动规划、路径规划及轨迹规划简介之一
    March 11th, 2018 Week 11th Sunday
    March 10th, 2018 Week 10th Saturday
    March 09th, 2018 Week 10th Friday
    March 08th, 2018 Week 10th Thursday
    March 07th, 2018 Week 10th Wednesday
    ubantu之Git使用
    AMS分析 -- 启动过程
  • 原文地址:https://www.cnblogs.com/ringwang/p/1918420.html
Copyright © 2020-2023  润新知