前台:
function GetFocus()
{
if(event.keyCode==13)
{
document.getElementById("Button1").click();
return false;
}
}
后台:
TextBox1.Attributes.Add("onkeydown","return GetFocus();");
或者:
<SCRIPT LANGUAGE="javascript">
function SubmitKeyClick(button)
{
if (event.keyCode == 13)
{
if(event.srcElement.id=="tbInput")
{
event.keyCode=9;
event.returnValue = false;
document.all[button].click();
}
}
}
// -->
</SCRIPT>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1、将页面上所有回车事件都绑定到一个按钮上
<HEAD>
<script language="javascript">
function EnterTextBox()
{
if(event.keyCode == 13 && document.all["TextBox1"].value != "")
{
event.keyCode = 9;
event.returnValue = false;
document.all["Button1"].click();
}
}
</script>
</HEAD>
<body onkeypress="return EnterTextBox()">
2.不同的TextBox绑定不同的Button
<HEAD>
<script language="javascript">
function EnterTextBox(button)
{
if(event.keyCode == 13)
{
event.keyCode = 9;
event.returnValue = false;
document.all[button].click();
}
}
</script>
</HEAD>
在对应的cs文件中
//绑定TextBox回车事件
TextBoxPortOfDestination
.Attributes.Add("onkeypress", "EnterTextBox('ButtonChoose')");
TextBoxItemName.Attributes.Add("onkeypress","EnterTextBox('ButtonAdd')");
TextBoxCost_PX.Attributes.Add("onkeypress","EnterTextBox('ButtonAdd')");
TextBoxCost_1X20.Attributes.Add("onkeypress","EnterTextBox('ButtonAdd')");