以下代码
<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
又没有什么简单的办法?
<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
又没有什么简单的办法?
<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>你要在里面加上判断即可