JavaScript函数仅在Edge而不是Chrome,Firefox或Opera中起作用



我正在尝试制作一个可用于所有浏览器的JS函数。当用户单击Enter并单击文本框(ASP(

时,我正在使用以下功能按下按钮

此JavaScript函数仅在边缘起作用,但不适用于Chrome,Firefox或Opera:

function button_click(objTextBox, objBtnID) {
    if (window.event.keyCode === 13) {
        document.getElementById(objBtnID).focus();
        document.getElementById(objBtnID).click();
    }
}

CS代码:

Password.Attributes.Add("onkeypress", "button_click(this,'" + LogIn.ClientID + "')");

跨浏览器支持中有任何建议?

预先感谢。

我看到您正在使用asp.net。您可以在HTML代码中使用此示例来选择一个默认按钮,该按钮将通过按Enter

来激活。
<asp:Panel ID="Panel1" runat="server" DefaultButton="LogIn">
        <p class="InfoText">Username:</p>
        <asp:TextBox ID="Username" runat="server"></asp:TextBox>
        <p class="InfoText">Password:</p>
        <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
</asp:Panel>

希望这会有所帮助。

最新更新