【问题标题】:IE lose focus after field has been clicked into点击字段后 IE 失去焦点
【发布时间】:2011-10-13 16:08:37
【问题描述】:

我有一个错误层显示在无效/空白条目的表单上。当出现该错误层时,我希望当前字段失去焦点。在 IE 中,我无法让它工作。焦点始终留在现场。

    <!--Jquery function to override JS alert with DOM layer alert message-->
function customAlert(){
    var args = arguments;
    if(args.length > 1) {
        // check that custom alert was called with at least two arguments
        var msg = args[0];

        $("li").removeClass("alertRed");
        $("input").removeClass("CO_form_alert");
        $("select").removeClass("CO_form_alert");
        var div = $(".errorPopup");
        div.css({"display":"block"});


        if (div.length == 0) {
            div = $("<div class='errorPopup' onclick='$(this).hide();'></div>");
            $("body").prepend(div);
        }
        div.html(msg);
        for(var i = 1; i < args.length; i++) {
            var inputID = args[i];
           $("#"+inputID).addClass("CO_form_alert").parent().addClass("alertRed");
            $("input,select,radio,checkbox").focus(function(){
                $(this).unbind('focus'); // remove this handler
                $('.errorPopup').hide(); // hide error popup

            });


        }
     }
}

我试过 ('body').focus();和 $("#"+inputID).focusout();这也行不通。

我也试过了:

div.css({"display":"block"});
$("input,select,radio,checkbox").blur();

和

$("input,select,radio,checkbox").blur(function(){
                $(this).unbind('focus'); // remove this handler
                $('.errorPopup').hide(); // hide error popup

            });

但没有一个工作。

【问题讨论】:

    标签: javascript jquery internet-explorer error-handling focus


    【解决方案1】:

    使用模糊方法。

    $("input,select,radio,checkbox").blur();
    

    【讨论】:

    • 你可以再做一件事。将 tabIndex="-1" 设置为错误容器,然后在显示时将焦点设置为错误容器。你可以说 $("errorContainerSelector").focus();
    • 也试过了。它似乎在 IE 中挂起一秒钟,然后焦点/光标仍留在该字段中
    【解决方案2】:

    你试过了吗

    $("input,select,radio,checkbox").blur();
    

    ?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-31
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 2012-04-30
      相关资源
      最近更新 更多