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

$(’。report_filter input’)获取所选单选框的值,将变量发送到函数report_operation,从那里我根据选择隐藏一些字段

$(“。js-ajax-php-json”)ajax表单提交,我想进入.submit里面的var值。 在那里我可以做一些如果空字段返回false以停止提交表单。 例如,如果field name =“number”为空且var值为1则返回false; 这不能通过简单的表单validation器来完成,它是一种非常动态的表单。

我根本不知道该怎么做

$('.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(); } }