按钮onclick 单击 触发jquery.validate 验证

本文介绍了如何在JavaScript中设置按钮的onclick事件,触发Jquery.validate插件进行表单验证。详细步骤包括配置验证规则和响应点击事件,确保用户输入符合指定要求。
摘要由CSDN通过智能技术生成
  function validateForm() {
             return $("#mainForm").validate({
                errorElement: "em",
                rules: {
                    name: {
                        required:  true,
                        remote: {
                            type: "POST",
                            url: "/plant/check",
                            data: {
                                pname:  function() {  return $("#name").val(); },
                                pid:  function() {  return $("#id").val(); }
                            }
                        }
                    },
                    design_power:
                    {
                        required:  true,
                        number:  true
                    }
                },
                messages: {

                    name: {
                        required: '',
                        remote: ""

                    },
                    longitude: {
                        number: '',
                        max: '',
                        min: ''
                    },
                    latitude: {
                        number: '',
                        max: '',
                        min: ''
                    },
                    design_power: {
                        required: "",
                        number: ''
                    },
                    email: {
                        email: ""
                    }
                },
                errorPlacement:  function(error, element) {
                    parent.iframeauto();
                     if (document.getElementById("error_" + element.attr("name"))) {
                        error.appendTo("#error_" + element.attr("name"));
                    }
                     else
                        error.insertAfter(element);

                },
                success:  function(em) {

                }
            }).form();
           
        }

 

     // 执行提交表单  体检之前先验证填写是否正确
         function execute(issubmit) {
             if (validateForm() && issubmit)
                document.forms[0].submit();
             return validateForm();
        }

 转载请注明:http://www.liebo6.com

转载于:https://www.cnblogs.com/luckychbo/archive/2012/10/26/2740630.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值