English 中文(简体)
jj 查询窗体错误迭代
原标题:jQuery form error iterations

我有一个jQuery 表格, 如果用户不正确填写此代码的表格, 可以显示消息 :

if (errorList.length > 0) {
                    permitted = false;

                    //Display error message
                    $("#" + stepName + " legend").after("<div id="errorList" class="error"><h3>Please correct the following </h3><ul></ul></div>");
                    for (var j = 0; j < errorList.length; j++) {
                        if (errorList[j] != undefined)
                            $("#errorList ul").append("<li>" + errorList[j] + "</li>");
                    }

                }

问题在于当用户试图多次提交有错误的表格时,就会发生这种情况:

""https://i.sstatic.net/LX0RF.png" alt="此处的内置图像描述"/"

我该如何解决这个问题?

最佳回答

在迭代之前添加 < code>. 空 。

$("#errorList ul").empty();
for(var j = 0; j < errorList.length; j++) {
if (errorList[j] != undefined)
    $("#errorList ul").append("<li>" + errorList[j] + "</li>");
}
问题回答

尝试 :

           if (errorList.length > 0) {
                permitted = false;

                //Display error message
                $("#" + stepName + " legend").after("<div id="errorList" class="error"><h3>Please correct the following </h3><ul></ul></div>");
                $("#errorList ul").empty(); // THIS FIXES IT
                for (var j = 0; j < errorList.length; j++) {
                    if (errorList[j] != undefined)
                        $("#errorList ul").append("<li>" + errorList[j] + "</li>");
                }

            }




相关问题
Bind Button.IsEnabled to custom validation with XAML?

I am sorry I didn t know how to title my question any better, you name it if you got a good 1. I have an entity Contact. this person has navigation properties: Address, Phones (A collection of Phone)....

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

Rails 101 | validates_currency?

I ve searched high and low, but I could not find a solution, to what I think seems like a very common task. In a form I want to have a text input that accepts currency strings (i.e. $1,000,000 or ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签