Bobby

聚沙成塔 集腋成裘
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

asp.net回车提交表单

Posted on 2007-09-11 05:02  Bobby  阅读(1767)  评论(0编辑  收藏  举报
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;}");