asp.net实现Ctrl+回车提交实例
在使用QQ时使用Ctrl+回车来发送信息是不是很方便,那个在网页中如何用Ctrl+回车来直接提交数据呢?下面我们以ASP.NET编程为例子,实现Ctrl+回车提交数据。下面看源码: ASP.NET前台HTMl代
在使用QQ时使用Ctrl+回车来发送信息是不是很方便,那个在网页中如何用Ctrl+回车来直接提交数据呢?下面我们以ASP.NET编程为例子,实现Ctrl+回车提交数据。下面看源码:
ASP.NET前台HTMl代码:
HTML Code [http://www.xueit.com]
1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Submit.aspx.cs" Inherits="test_Submit" %> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3 <html xmlns="http://www.w3.org/1999/xhtml"> 4 <head runat="server"> 5 <title>asp.net Ctrl 回车提交</title> 6 <script type="text/javascript"> 7 //这种提交在asp.net下不会执行后台代码 8 function submitForm(formName) { 9 if(window.event.ctrlKey&&window.event.keyCode==13) { 10 document.getElementById(formName).submit(); 11 } 12 } 13 //相当于按了一下提交按钮,所以此法在asp.net可行 14 function clickButton() { 15 if(window.event.ctrlKey&&window.event.keyCode==13) { 16 document.getElementById("btnOk").click(); 17 } 18 } 19 </script> 20 </head> 21 <body> 22 <form id="form1" runat="server" name="form1"> 23 <div> 24 <asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" onkeydown="submitForm(this.form.name);"></asp:TextBox> 25 <br /> 26 <asp:TextBox ID="txtBody" runat="server" TextMode="MultiLine" onkeydown="clickButton();"></asp:TextBox> 27 <br /> 28 <asp:Button ID="btnOk" runat="server" Text="提交" onclick="btnOk_Click" /> 29 </div> 30 </form> 31 </body> 32 </html>
以下是Asp.Net后台cs代码:
C# Code [http://www.xueit.com]
1 using System; 2 using System.Collections; 3 using System.Configuration; 4 using System.Data; 5 using System.Linq; 6 using System.Web; 7 using System.Web.Security; 8 using System.Web.UI; 9 using System.Web.UI.HtmlControls; 10 using System.Web.UI.WebControls; 11 using System.Web.UI.WebControls.WebParts; 12 using System.Xml.Linq; 13 14 public partial class test_Submit : System.Web.UI.Page 15 { 16 protected void Page_Load(object sender, EventArgs e) 17 { 18 19 } 20 protected void btnOk_Click(object sender, EventArgs e) 21 { 22 Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('提交成功!')</script>", false); 23 } 24 }
以上代码就这么简单就实现了Ctrl+回车提交了。
精彩图集
精彩文章
热门标签
kindeditor编辑
python语音
cps
加载数据
mysql多实例
表单
win2003服务器
tab文件操作类
ins_ctx.mk
混合使用
空字
python代码检查
administrato
类型关键字
以斜杠结尾
PHP PHP递归
是什么
显示图表
中文字段
downsample
Win32_PingSt
APC安装配置
事务
静态成员
大类
nosql优点
初始化列表
php递归
循环链表
刷票
拼接字符串
Mongodb
shift
va_end
几个星期
线程并发
Sublime
一个元素
鼠标样式
VBS基础教程
还是
文件打包zip
分出
快站
索引器
追踪器
Innotop
PHP安全
JPA
无刷新
php php中动
输入地
Ftp下载[1
line-block
HTML:scrollL
合计
PHP PHP 访问 G
默认controller
文件名
特殊图案
赞助商链接
@CopyRight 2002-2008, 1SOHU.COM, Inc. All Rights Reserved QQ:1010969229

