我有一个page1.php,我有一个fly.php。page1.php是一个简单的(常规)表单页面,当用户提交表单时,人们会在其中放置信息。
问题:How can i after .submit() pause for validatio此验证码中的n个,并在验证成功之后,恢复表单提交(处于保留状态)?
How can i after .submit() pause for validatio
例:
第1部分:page1.php
$(document).ready(function() { $('.callmeback').submit(function() { $.ajax({ type : "GET", url : "/include/class/fly.php", data : "a=b", async : false, beforeSend: function() { $(document.body).find('.blackwindow').remove(); $(document.body).find('.nospam').remove(); }, complete: function() { }, success : function(msg) { $(document.body).append(msg); $('.blackwindow').css({ 'opacity':'0.90' }); $('.nospam').find('input[type="button"]').live("click", function() { // final validation var security= $('.nospam').find('#security').val(); var random = $('.nospam').find('#random').val(); if (random!=security) { alert ('Invalid captcha.'); return false; } else { // Basically its second time? and return true? } }); } }); //return false; }); }); <form method=post action=thanks.php class="callmeback"> <input type=text value=100.00 name=amount /> <input type=submit value=submit name=submit /> </form>
第2部分:fly.php
<? require_once 'obj.php';?> .blackwindow { position:fixed; top:0px; left:0px; width:100%; height:100%; z-index:1000; background-color:#000000; } .nospam { position:fixed; top:30%; left:30%; padding:12px; border:solid 3px #686868; background-color:#ffffff; z-index:1001; } <div class="blackwindow"></div> <div class="nospam"> <div> <? $value = obj::getRandom(); echo '<img src="include/class/return_img.php?number=' . $value . '" />'; echo "<input type='hidden' id='random' name='random' value='$value' />"; ?> <div> *Please enter the above code below, to verify this request <br/> <input type="text" class="textbox" id="security" name="security" /> </div> </div> <div> <input type=button name=mybutton value="Verify" /> </div> </div>
跟进(校对):
$(document).ready(function() { $('.callmeback').find('input[type="button"]').live("click", function() { $.ajax({ type : "GET", url : "/include/class/fly.php", data : "a=b", async : false, beforeSend: function() { $(document.body).find('.blackwindow').remove(); $(document.body).find('.nospam').remove(); }, complete: function() { }, success : function(msg) { $(document.body).append(msg); $('.blackwindow').css({ 'opacity':'0.90' }); $('.nospam').find('input[type="button"]').live("click", function() { // final validation var security= $('.nospam').find('#security').val(); var random = $('.nospam').find('#random').val(); if (random!=security) { alert ('Invalid captcha.'); return false; } else { $('.callmeback').submit(); } }); } }); //return false; }); });
最简单的方法是使“提交”按钮实际上不是<input type='submit'>按钮,而只是一个标准按钮button。如果通过验证,则可以使用$('form').submit()或类似方式手动提交论坛。
<input type='submit'>
button
$('form').submit()