ASP.Net 实现按回车触发事件 就是我的页面上有一个textBox,我要实现在其中输入一些数字后按回车触发执行操作,关键是如何实现按回车触发,求大牛指点~~~~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function keyDown(evt){ if(isEvent(evt).which==13){//回车 ajax//方法你要执行的代码 } } <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_20120301_Default" %><!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>无标题页</title> <script src="../jquery-1.3.2-vsdoc.js" type="text/javascript"></script> <script type="text/javascript"> //回车事件 $(window).keydown(function(event){ if(event.keyCode == 13) { alert("TextBox1的值为:" + $("[id$=TextBox1]").val()); } }); </script> </head><body> <form id="form1" runat="server"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </form></body></html> <asp:TextBox onkeydown="if(event.keyCode==13) alert('xx')" js是在前台运行,写后台怎么执行?后台添加也是这样TextBox1.Attributes.Add("onkeydown","alert('x')") $(document).keydown(function(e){ if(e.keyCode==13){document.getElementById("<%=btnclick.ClientID%>").click();}}) event.keyCode==13判断一下这个就行了 我怎么将这个函数与页面上的textbox 关联起来呢? this.TextBox1.Attributes.Add("onkeydown", "if(event.keyCode==13) {document.all." + this.button1.ClientID + ".focus();document.all." + this.button1.ClientID + ".click();}");//当按下回车键时,让指定的按钮获取指定的文本框的事件 可以运用ajax,脚本调用后台方法,数据库查询返回结果字符串,在前台把字符串在页面显示,如:前台脚本: $(window).keydown(function(event){ if(event.keyCode == 13) { //调用后台方法 WebForm1.m_search_Click(price1, price2, type, function (response) { if (response.value != undefined && response.value != "") { $('#aaa').html(response.value); } }); } }); WebForm1:后台文件名字m_search_Click:方法名后台:protected void Page_Load(object sender, EventArgs e) { Ajax.Utility.RegisterTypeForAjax(typeof(WebTest.WebForm1)); //WebTest为命名空间 } [Ajax.AjaxMethod] public string m_search_Click(decimal price1,decimal price2,string type) { StringBuilder sb = new StringBuilder(); //调用方法,实现查询 sb.Append("<option>Choose a Status...</option>"); return sb.ToString(); }webconfig: <handlers> <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/> </handlers> $("#<%=TextBox1.ClientID%>").keydown(function(e){if(e.keyCode==13){document.getElementById("<%=btnclick.ClientID%>").click();}}) 可以不加按钮么?我只在页面放一个TextBox,在其中输入一个id按回车然后在数据库中查询 后台C#代码如何写将其与textbox关联起来? $("#<%=TextBox1.ClientID%>").keydown(function(e){if(e.keyCode==13){document.forms[0].submit();}}) 正解,有必要了解下GET POST 等一些WEB开发的基础知识 Ajax 没用过,想学学但不知道怎么开头,用的比较笨的方法,不过还是谢谢大家。 C#动态生成大量<div>,并且id带不同参数 弹出提示窗口的问题 问个简单的问题,就是在VISAUL STUDIO 中写在每个类文件前的说明 请教:bt3.btchina.net中这样的表格效果是怎么做出来的啊? 关于三层菜单的数据库设计问题 请高手帮忙讲解一下Request的使用 请问怎样复用一个页面的某一部分?具体见下,谢谢! 关于用gridview中显示内容的问题 新手求ASP.NET项目教程啊,看教程熟悉一下ASP.NET, mvc如何返回一个完整的html 如何在.net中编写xhtml网页? 怎样循环datatable中的数据,并且添加到list集合中。
if(isEvent(evt).which==13){//回车
ajax//方法你要执行的代码
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title> <script src="../jquery-1.3.2-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript">
//回车事件
$(window).keydown(function(event){
if(event.keyCode == 13) {
alert("TextBox1的值为:" + $("[id$=TextBox1]").val());
}
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>
TextBox1.Attributes.Add("onkeydown","alert('x')")
if(e.keyCode==13)
{
document.getElementById("<%=btnclick.ClientID%>").click();
}})
判断一下这个就行了
我怎么将这个函数与页面上的textbox 关联起来呢?
this.TextBox1.Attributes.Add("onkeydown", "if(event.keyCode==13) {document.all." + this.button1.ClientID + ".focus();document.all." + this.button1.ClientID + ".click();}");//当按下回车键时,让指定的按钮获取指定的文本框的事件
前台脚本:
$(window).keydown(function(event){
if(event.keyCode == 13) {
//调用后台方法
WebForm1.m_search_Click(price1, price2, type, function (response) {
if (response.value != undefined && response.value != "") {
$('#aaa').html(response.value);
}
});
}
}); WebForm1:后台文件名字
m_search_Click:方法名
后台:protected void Page_Load(object sender, EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(WebTest.WebForm1)); //WebTest为命名空间
}
[Ajax.AjaxMethod]
public string m_search_Click(decimal price1,decimal price2,string type)
{
StringBuilder sb = new StringBuilder();
//调用方法,实现查询
sb.Append("<option>Choose a Status...</option>"); return sb.ToString();
}
webconfig:
<handlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
</handlers>
if(e.keyCode==13)
{
document.getElementById("<%=btnclick.ClientID%>").click();
}})
可以不加按钮么?我只在页面放一个TextBox,在其中输入一个id按回车然后在数据库中查询 后台C#代码如何写将其与textbox关联起来?
if(e.keyCode==13)
{
document.forms[0].submit();
}})