现在的位置: 首页 > 综合 > 正文

asp.net回车提交表单

2012年08月05日 ⁄ 综合 ⁄ 共 1675字 ⁄ 字号 评论关闭
ASP.NET页面按回车提交表单,前台页面

  <script type="text/javascript">
    
function check()
    
{
  
        
var theForm = document.forms['aspnetForm'];
   
 
        
if(theForm.ctl00$ContentPlaceHolder1$txtUserName.value=="")
        
{
            alert(
"请输入用户名!");
            theForm.ctl00$ContentPlaceHolder1$txtUserName.focus();
            
return false
        }
            
        
        
var myRegex = /@.*\.[a-z]{2,6}/;
        
var email = theForm.ctl00$ContentPlaceHolder1$txtUserName.value;
        email 
= email.replace(/^ | $/g,"");
        email 
= email.replace(/^\.*|\.*$/g,"");
        email 
= email.toLowerCase();        
       
        
if (!myRegex.test(email))
        
{
            alert (
"请输入有效的E-Mail!");
            theForm.ctl00$ContentPlaceHolder1$txtUserName.focus();
            
return false;
        }

    
        
if(theForm.ctl00$ContentPlaceHolder1$txtPassword.value=="")
        
{
            alert(
"请输入密码!");
            theForm.ctl00$ContentPlaceHolder1$txtPassword.focus();
            
return false;
        }

        
        
return true;
     
        
    }
 
    
    
function checksearch()
    
{
        
var Form = document.forms['aspnetForm'];
        
if(Form.ctl00$ContentPlaceHolder1$SearchText.focus)
        
{
            
if(Form.ctl00$ContentPlaceHolder1$SearchText.value=="")
            
{       
                alert(
"请输入关键字!");
                Form.ctl00$ContentPlaceHolder1$SearchText.focus();
                
return false;
            }

            
return true;   
        }

    }

    
</script>

后台:


          //添加属性,JS代码用来判断回车键
            SearchText.Attributes.Add("onkeydown", "if (event.keyCode == 13){aspnetForm.ctl00$ContentPlaceHolder1$btnSearch.click();return false;;return false;}");
          

抱歉!评论已关闭.