【发布时间】: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