English 中文(简体)
j Query Validate on Blur with summary
原标题:jQuery Validate onBlur with summary

试图验证我不了解该页内容的表格,并在该页顶上使用j Query Validate进行总结。 我不想向每一个领域发出信息。 我可以在提交书上获得罚款,如果我不重视重点/目标/任务,一切都只会奏效。 目前,我一直试图通过显示错误来做到这一点,但我持开放态度。

我的印象是,j Query Validate只带回在燃烧或 key火时失败的单一元素。 现在发生的情况是,我的总结每次都翻了字,当它火上).时,摘要可以 empty空(假定错误只包括一个失败的内容)。 我喜欢更新或更新我的总结,以便在用户通过表格时保持正确性。

我认为,我可能需要避免提及我的验证人,然后通过有效验证人进行选择。 错误或错误,但我不敢肯定会采取这种做法。 下面是我从任何纽芬兰语被点击的整个验证功能。

function validateform() {

$("form").validate({

    showErrors: function(errorMap, errorList) {

        var errorCount = this.numberOfInvalids();

        if (errorCount > 0) {
            if (errorCount == 1) {
                $("#errorContainer h3").html("Your form contains " + errorCount + " error, see details below.");
            }
            else { /*two or more errors */
                $("#errorContainer h3").html("Your form contains " + errorCount + " errors, see details below.");
            }
            var summary =   ;

            $.each(errorMap, function(key, value) {
                var field = $( input[name="  + key +  "],select[name="  + key +  "],textarea[name="  + key +  "] );
                field.addClass( err );
                var fieldname = field.attr("rel");
                summary +=  <p><span class="errorkey">  + fieldname +  </span> - <span class="errorvalue">  + value + "</span></p>";
            });
            $( #errorList ).html(summary);
            $( #errorContainer ).slideDown();
        }
    },
    onfocusout: false,
    onkeyup: false,
    onclick: false

});
}
问题回答

假设这一形式:

<div id="errorContainer"></div>
<form id="myform">
    <div>
        <label for="field1">field1</label>
        <input type="text" id="field1" name="field1" />
    </div>
    <div>
        <label for="field2">field2</label>
        <input type="text" id="field2" name="field2" />
    </div>
</form>

你们可以做这样的事情,以纠正错误,将其放在一个概述部分:

$(function () {
    var
        container = $("#errorContainer"),
        validator = $("#myform").validate({
            rules: {
                field1: {
                    minlength: 2,
                    required: true
                },
                field2: {
                    required: true
                }
            },
            messages: {
                field1: {
                    minlength: "Please enter 2 or more characters for field1",
                    required: "Please enter field1"
                },
                field2: {
                    required: "Please enter field 2"
                }
            },
            onfocusout: function (element) {
                this.element(element);
            },
            errorPlacement: function (error, element) {
                var
                existingErSelector = $.validator.format("label[for={0}]:contains({1})", element.attr("id"), error.text());

                if (container.find(existingErSelector).length === 0) {
                    $("#errorContainer ").append(error);
                }
            },
            unhighlight: function (validElement) {
                container.find($.validator.format("label[for={0}]", validElement.id)).remove();
            }
        });
});

见http://jsfiddle.net/richwag/AjXqp/5/"rel=“nofollow”http://jsfiddle.net/richwag/AjXqp/5/





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签