Javascript 将变量从函数传递到提交函数

Javascript 将变量从函数传递到提交函数,javascript,jquery,Javascript,Jquery,$('.report_filter input')获取所选单选框的值,该单选框将变量发送到函数report_操作,然后根据选择隐藏一些字段 $(“.js ajax php json”)ajax表单提交,我想进入.submit var值的内部。在那里,如果空字段返回false,我可以执行一些操作来阻止表单提交。例如,如果字段name=“number”为空且var值为1,则返回false;这不能由一个简单的表单验证程序实现,它是一个相当动态的表单 我只是不知道该怎么做 $('.report_filt

$('.report_filter input')获取所选单选框的值,该单选框将变量发送到函数report_操作,然后根据选择隐藏一些字段

$(“.js ajax php json”)ajax表单提交,我想进入.submit var值的内部。在那里,如果空字段返回false,我可以执行一些操作来阻止表单提交。例如,如果字段name=“number”为空且var值为1,则返回false;这不能由一个简单的表单验证程序实现,它是一个相当动态的表单

我只是不知道该怎么做

$('.report_filter input').on('ifChecked', function(event){
                             var val = $(this).val();
                             raport_operation(val);
                        });

                            $(".js-ajax-php-json").submit(function(){
                            var data = {
                              "action": "test1"
                            };
                            data = $(this).serialize() + "&" + $.param(data);
                            alert(raport_operation());
                                // if ($("#number").val() == "" and val == 1) {
                                // alert('you did not fill out one of the fields');
                                // return false;
                                // }
                            $.ajax({
                              type: "POST",
                              dataType: "json",
                              url: "api/response.php",
                              data: data,
                              success: function(data) {
                              draw_graph(data);
                                $(".the-return").html(data);
                                //alert("Form submitted successfully.\nReturned json: " + data["json"]);
                              }
                            });
                            return false;
                      });


                        function raport_operation(query){
                            //alert(val);
                            if(query==1){ //number
                                //alert(1);
                                $('#segment_optional').hide('slow');
                                $('#segment_number').show('slow');
                                $('#segment_optional').show('slow');
                                $('#segment_customer').hide('slow');
                                $('#segment_listType').hide('slow');
                                $('#segment_customer').val('');
                                $('#reportdate_to').val('');
                                $('#reportdate_from').val('');
                                // $('#segment_general').hide();
                            }
    }

您在ajax中的数据是什么样子的?@SebastianBochan我自己就知道了:)它是以我忘记的形式传递的