📌  相关文章
📜  jquery 验证错误放置 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:27.733000             🧑  作者: Mango

代码示例1
$(document).ready(function () {
    $('#add_client').validate({
        errorClass: 'validation_errors',
        debug: false,
        rules: {
            client_name: {
                required: true
            },
            client_address: {
                required: true
            },
            client_city: {
                required: true
            }
        },
        errorPlacement: function (error, element) {
            console.log('dd', element.attr("name"))
            if (element.attr("name") == "client_city") {
                error.appendTo("#messageBox");
            } else {
                error.insertAfter(element)
            }
        },
        messages: {
            client_name: {
                required: "The Client name is a required / mandatory field"
            },
            client_address: {
                required: "The Client address is a required / mandatory field"
            },
            client_city: {
                required: "The City is a required / mandatory field"
            },

        },
        submitHandler: () => {
        $('#send_form').on('click', submitFormHandler)
        $('#send_form').trigger('click')
        $('#terms-of-use').removeClass("checked")
        $('#terms').removeClass("checked")
      }
    });
});