【问题标题】:dropdown focus on page and enter key press check using jquery/javascript下拉焦点在页面上并使用 jquery/javascript 输入按键检查
【发布时间】:2010-01-21 02:36:56
【问题描述】:

带有焦点的下拉菜单并按下输入键验证表单。

我有一个表单,其中包含由 jquery 验证的元素(在下面的验证器函数中) 如果我有一个文本框,并且启用焦点并按下回车键,我将获得所有 Javascript 验证。

$( document ).ready(function() {
        var container = $('div.errors');

            $("mydropdownId").focus(); //tried this , focus works, but enter key press check  doesn't work 
            // validate the form when it is submitted
        var validator = $("#coverageForm").validate({
        invalidHandler: function() {
            $('#form_error_notice').css('display', 'block');
            $('.server_error_notice').css('display', 'none');
                $('.errorsServer').css('display', 'none');
                hintAgain();
        },
         submitHandler: function(){

            DoDisable(); //changes couple of divs and does document.form.submit();
            },
      errorContainer: $("#coverageForm .errors"),
                errorLabelContainer: $("ul", "#coverageForm .errors"),
                    wrapper: 'li',
                    meta: "validate"
        });
    // Control input in numeric form fields
    $('input.numeric').numeric();
    // Initiate overlays
    $('.boxy').boxy({modal: true});
});

我是 jquery 的新手,谁能引导我走向光明?我不想更改 jquery 提供的验证。这是我的“客户”的严格要求!

提前致谢!

【问题讨论】:

    标签: javascript jquery drop-down-menu


    【解决方案1】:

    html 表单的默认行为是,当您单击 enter 时,表单被提交。这样就会启动 JQuery.Validator 来验证表单上的字段。

    所以要解决这个问题,您可能必须捕获 keydown 或 keypress 事件,按下回车键,然后手动移动到下一个字段(调用下一个控件上的焦点)

    【讨论】:

    • 克里斯,我不打算捕获 keydown/keypress。我在表单中验证了 jquery。我希望在输入键时进行相同的验证 - 你的想法为什么这可能不起作用!
    猜你喜欢
    • 2012-07-11
    • 1970-01-01
    • 2011-08-18
    • 2016-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多