嘿家伙真的不知道如何措辞,但即使我已经添加required
到我的表单输入,它运行 JavaScript onsubmit 甚至在required
按下按钮和表单空白时失败。
当按下按钮并且表单为空白时,我可以在我的 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>
Java脚本
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);
});
});