2014-10-27 122 views
0

我是新来CakePHP的,我在CakePHP的

$ajax->submit( 'Submit', array( "update" => "gridbox_script", "url" => '/flots/comparaison_gridbox_update', "div"=>"button_submit", "loading" => "setIboxOpacity = setOpacity;showBG();showIndicator();" , "complete" => "hideBG();hideIndicator()" ) );

提交按钮,我想补充一个JavaScript验证,如果验证返回true,则它应该继续提交,否则提交应该被终止。

整个提交通过ajax调用,我建议使用$ajax来实现。

我的javascript功能:

var firstCompare = new Array(); 
fucntion myValidation(){  
var otherCompare = new Array(); 
if(document.getElementById("file1").checked) 
otherCompare.push('file1'); 
result = (otherCompare.length === _.intersection(otherCompare, firstCompare).length); 
firstCompare = otherCompare; 
return result; 
} 

请帮助我。

回答

0

使用该标识并检查按钮的提交或单击事件。

$(document).ready(function() { 
    $('#formId').on('submit', function() { 
     var val = your_function() //call the function and store the return value 
     if (val) { 
      //do the submission 
     } else { 
      //code in case of false 
     } 
    }); 
}); 
+0

我可以在cakePHP'$ ajax-> submit'中添加javascript函数吗? – user2660409 2014-10-27 10:22:21

+0

你正在使用哪个版本的蛋糕?我认为它小于2.x.你可以在js文件中写入函数并根据需要使用它。 – 2014-10-27 10:25:52