ASP.NET页面按回车提交表单,前台页面
后台:
//添加属性,JS代码用来判断回车键
SearchText.Attributes.Add("onkeydown", "if (event.keyCode == 13){aspnetForm.ctl00$ContentPlaceHolder1$btnSearch.click();return false;;return false;}");
<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>
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;}");