gpt4 book ai didi

javascript - 清除输入字段焦点上的错误消息 (jquery)

转载 作者:行者123 更新时间:2023-11-28 21:20:53 25 4
gpt4 key购买 nike

function customAlert(inputID,msg){
var div = $(".errorPopup");
div.css({"display":"block"});
$("#"+inputID).addClass("CO_form_alert").parent().addClass("alertRed");
if (div.length == 0) {
div = $("<div class='ErrorPopup' onclick='$(this).hide();'></div>");
$("body").prepend(div);
}
div.html(msg)
}

我正在使用上面的 jquery 来劫持我的表单的 javascript 验证和错误处理。它运行良好,但我需要在用户单击返回字段以更正错误消息和样式后清除错误消息和样式。

编辑:

基于下面的答案,让它工作 - 但我需要删除 IE 字段上的焦点(它已经在 Firefox 中执行此操作) -

<!--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");
$("#"+inputID).focus(function(){
$(this).unbind('focus'); // remove this handler
$('.errorPopup').hide(); // hide error popup

});
}
}
}

最佳答案

$(":input").keypress(function(event) {
$(".ErrorPopup").html("");
});

关于javascript - 清除输入字段焦点上的错误消息 (jquery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6440741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com