同一个服务器端form里面的submit问题

ForMyBrian 2007-02-12 02:57:00
以下代码
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<input type="text" id="txt1" />
<asp:Button ID="Button1" runat="server" Text="Button1" />
<input type="text" id="txt2" />
<asp:Button ID="btnSearch" runat="server" Text="Button2" />
</form>
</body>
</html>
每次在文本框里面输入以后按回车键,默认都会执行button1的submit,因为2个button触发的服务器端时间并不一样,我需要txt1里面回车触发button1的submit,txt2里面的回车触发button2的submit
又没有什么简单的办法?
...全文
132 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
nov30th 2007-02-12
  • 打赏
  • 举报
回复
用JS截取Enter事件。

你可以改下我的代码

我这个是屏蔽Enter事件的。


<script type="text/javascript">
var Nav4 = document.layers;
var IE4 = document.all;

function enterkey(e)
{
//alert("In EnterKey function");

if (Nav4)
{
keyPressed = String.fromCharCode(e.which);
}

else if (IE4)
{
// alert("In IE4");
keyPressed = String.fromCharCode(window.event.keyCode);
}

if (keyPressed == "\r" || keyPressed == "\n")
{
// alert("In keypress");
return (false);
}
}

</script>

<script type="text/javascript">
if (window.document.captureEvents != null)
window.document.captureEvents(Event.KEYPRESS)
window.document.onkeypress = enterkey;
</script>

你要在里面加上判断即可

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧