zoukankan      html  css  js  c++  java
  • JS实现给页面表单设置触发默认按钮

    var defaultBtnId;
    function setDefaultButton(id) {
        defaultBtnId = id;
    }
    document.onkeydown = function (e) {
        var theEvent = window.event || e;
        var code = theEvent.keyCode || theEvent.which;
        if (code == 13) {
            if (typeof (defaultBtnId) != "undefined" && defaultBtnId != null) {
                $(":input[id$='" + defaultBtnId + "'].OperationButton").click();
                if (typeof (window.event) != "undefined") {
                    window.event.returnValue = false;
                }
            }
        }
    }

    使用(在表单域所在的DIV上加上onclick触发的按钮ID就行, 可以是动态ID):

                        <div class="border" onclick="setDefaultButton('SearchButton')">
                                <table class="noborder">
                                    <tr>
                                        <td class="label">
                                            <asp:Label runat="server" ID="EmployeeIdTitleLabel" Text="Employee ID"></asp:Label><em>*</em>
                                        </td>
                                        <td>
                                            <asp:TextBox runat="server" ID="EmployeeIdTextBox" CssClass="RequiredText" MaxLength="6"
                                                SkinID="IntegerRequired" Width="60px"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="EmployeeIdTextBoxRequiredFieldValidator" runat="server"
                                                ControlToValidate="EmployeeIdTextBox" ValidationGroup="Search" ErrorMessage="[Employee ID] is required, please re-input."
                                                Display="None"></asp:RequiredFieldValidator>
                                        </td>
                                        <td>
                                            <asp:Button runat="server" SkinID="OperationButton" Text="Search" OnClick="SearchButton_Click"
                                                OnClientClick="return CallValidate('Search');" ID="SearchButton" ValidationGroup="Search"
                                                CommandName="Search" />
                                        </td>
                                    </tr>
                                </table>
                            </div>
  • 相关阅读:
    mtr-网络分析工具
    vpc是什么
    openstack安全组
    nginx服务器有什么作用?什么叫反向代理?为什么要使用反向代理?
    rpm 命令详解
    跟踪路由
    网卡配置bond(绑定)
    核心交换机、汇聚交换机是什么
    U盘制作Linux镜像
    11.MySQL 慢日志PT分析 可视化
  • 原文地址:https://www.cnblogs.com/xachary/p/3631153.html
Copyright © 2011-2022 走看看