案例如下:
一般情况下
当一个页面有TextBox以及Button的时候
当光标停留在TextBox上 此时按Enter键 回车
就会发现光标将焦点停留在Button上
并且触发了Button的按钮事件
本例实现如下效果
0.一个包含[姓名TextBox1]和[备注TextBox2]以及[确定Button按钮]的页面
1.屏蔽按钮对回车键的响应 而只响应鼠标的点击
2.以及实现Enter键->Tab键的转换
即TextBox1非空时 按回车键 光标转到TextBox2
当TextBox2非空时 按回车键 光标转到Button
当光标停留在Button上时 按回车键 光标转到TextBox1
---------------------------------------
相关代码示例如下:
1
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2"
%>
2 < html >
3 < head id ="Head1" runat ="server" >
4 < title > 屏蔽Button按钮对Enter键的响应 </ title >
5 < script language ="javascript" type ="text/javascript" >
6
7 //TextBox1的 onkeydown事件
8 //若TextBox1非空 则光标停留在TextBox2
9 function TextBox1onKeyDown()
10 {
11 if
2 < html >
3 < head id ="Head1" runat ="server" >
4 < title > 屏蔽Button按钮对Enter键的响应 </ title >
5 < script language ="javascript" type ="text/javascript" >
6
7 //TextBox1的 onkeydown事件
8 //若TextBox1非空 则光标停留在TextBox2
9 function TextBox1onKeyDown()
10 {
11 if