窗体onClick在窗体需求未运行时运行

窗体onClick在窗体需求未运行时运行

问题描述:

嘿,大家都不知道怎么说,但是即使我已经添加了required到我的窗体输入,它运行的JavaScript onsubmit甚至失败了required当按钮按下和形式空白。窗体onClick在窗体需求未运行时运行

有一条线,我可以添加到我的JavaScript从当按下按钮停止放送,而形式是空白的?任何帮助将是巨大的:d

<div id="div3"> 
    <div id="form"> 
     <form action="results.php" method="post" > 
     <input type="text" id="field" name="field" required> 
     <input id="submit" name="submit" type="image" src="gif/button.png" onClick="test();" value="submit"></form>  
    </div><div id="msg"><b> 
<span id="msgtxt">Hello</span> 
<span id="img"><img src="gif/loadingdot.gif"></span></b> 
</div> 
</div> 

Javascrpt

function test() 
{ 
    $('#msg').attr('style','display:block;'); 
    $('#msgtxt').html('Connecting To Server'); 

    setTimeout(function(){ //Beginning of code that should run AFTER the timeout 
    $('#msgtxt').html('Message one'); 
     //lots more code 
    },5000); // put the timeout here 
    setTimeout(function(){ //Beginning of code that should run AFTER the timeout 
    $('#msgtxt').html('Message two); 
     //lots more code 
    },7000); // put the timeout here 
    setTimeout(function(){ //Beginning of code that should run AFTER the timeout 
    $('#msgtxt').html('Message three'); 
     //lots more code 
    },11000); // put the timeout here 
    setTimeout(function(){ 
     txt=$("#field").val(); 
     $.post("results.php",{field:txt},function(result){ 
      $("#div3").html(result); 
     }); 
     $('#msg').attr('style','display:none;'); 
    },17000); 
} 

$(document).ready(function() { 
     $.post("form.html",{field:'mytext'},function(result){ 
      $("#load").html(result); 
     }); 
}); 

尝试:

<input id="submit" name="submit" type="image" src="gif/button.png" onClick="check();" value="submit"> 

,然后检查();功能:

var check = function(){ 
    if ($("#field").val() != "") 
     test(); 
    else 
     $('#msgtxt').html('form is empty'); 
} 
+0

感谢堆工作正常:) – Benjamin 2013-04-05 12:28:43