asp.net 实现回车替代Tab
2010-07-23 15:27
260 查看
最近一个客户需要在网页上按回车来实现Tab键的功能,我们说也是用Tab键来实现,可用户说他用Excel习惯了,所以此处也想这么操作,为了达到客户的需要,我们就这样做了。废话不多说,写个例子就明白了。
功能实现。但是这却有个问题,就是在最后的提交按钮点回车却不能提交了,只能点击鼠标实现提交。
把js改进一下即可实现了,改进后的js文件为:
ok!
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>回车键替代Tab测试</title> <script language="JavaScript" type="text/javascript"><!-- window.document.attachEvent("onkeydown" , function(){ if(window.event.keyCode==13){ window.event.keyCode = 9; } }); // --></script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server" AutoCompleteType="Department" TabIndex="1"></asp:TextBox><br /> <asp:TextBox ID="TextBox2" runat="server" TabIndex="2"></asp:TextBox><br /> <asp:TextBox ID="TextBox3" runat="server" TabIndex="3"></asp:TextBox> <br /> <asp:TextBox ID="TextBox4" runat="server" TabIndex="4"></asp:TextBox><br /> <asp:TextBox ID="TextBox5" runat="server" TabIndex="5"></asp:TextBox><br /> <asp:Button ID="Button1" runat="server" Text="提交" /></div> </form> </body> </html
功能实现。但是这却有个问题,就是在最后的提交按钮点回车却不能提交了,只能点击鼠标实现提交。
把js改进一下即可实现了,改进后的js文件为:
<script language="JavaScript" type="text/javascript"><!-- window.document.attachEvent("onkeydown", function() { var obj = document.activeElement; if (window.event.keyCode == 13 && obj.type != 'submit') { window.event.keyCode = 9; } }); // --></script>
ok!
相关文章推荐
- asp.net 实现回车替代Tab
- asp.net中实现在文本框按下回车键后相当于按下tab键focus跳到下一个文本框
- 在asp.net中实现回车替代Tab键
- C# 和 asp.Net 中用回车代替Tab键
- asp.net网页智能导航SmartNavigation的替代实现方式(C#保存)
- ASP.Net TextBox里面实现回车触发按钮事件
- asp.net中如何回车触发指定按钮的事件(实现按回车提交)
- asp.net中如何回车触发指定按钮的事件(实现按回车提交)
- asp.net中TextBox里面实现回车触发指定事件
- asp.net内实现在密码输入框内按回车就登陆的功能
- Asp.Net 实现线程传递多个参数。。。。。。。。。。。。。(并利用线程动态替代Word内的书签等)
- asp.net 各浏览器下实现回车提交表单
- ASP.NET让文本框只能输入数字的一种方法,外加回车换Tab
- asp.net中使用回车代替Tab键
- ReplaceTrim 函数之asp实现过滤掉字符中所有的tab和回车和换行的代码
- asp.net 实现按回车键执行提交事件
- asp.net中TextBox里面实现回车触发按钮button的解决方案
- 在asp.net中用回车代替tab