我正在尝试制作jQuery脚本,点击表单提交后会显示div:block并在5秒后提交我的表单。
下面的标题代码中的代码 - 即使是测试提交延迟也不起作用:
<script>
$('#registerform').submit(function (e) {
var form = this;
e.preventDefault();
setTimeout(function () {
form.submit();
}, 1000); // in milliseconds
});
</script>
此div应在以可见形式点击提交后显示:
<div id="gif"><img src="img/digital_signature.gif" /></div>
5秒后,此表格应提交:
<form action="todo.php" method="post" id="registerform">
<div class="input-holder">
<input class="fname" type="text" name="login" placeholder="Firstname">
</div>
<div class="input-holder">
<input class="fname" type="text" name="pass" placeholder="Lastname">
</div>
<div class="input-holder">
<input class="city" type="text" name="pass" placeholder="Postal Adress">
</div>
<div class="input-holder">
<input class="city" type="text" name="pass" placeholder="City">
</div>
<div class="input-holder">
<input class="city" type="text" name="pass" placeholder="Country">
</div>
<div class="input-holder">
<input class="email" type="text" name="pass" placeholder="E-mail">
</div>
<div class="input-holder">
<input class="revenue" type="text" name="pass" placeholder="Your Value">
</div>
<div class="input-holder">
<textarea rows="1" class="baddress" placeholder="Secret address"></textarea>
</div>
<div class="input-holder">
<input type="file" class="custom-file-input" name="SCAN" id="fileToUpload" />
</div>
<input type="submit" value="Login" id="submit">
</form>
答案 0 :(得分:2)
http://codepen.io/anon/pen/gPayYe
$('#submit').on('click', function (e) {
alert('button clicked: submitting in 5 seconds')
$('#gif').show();
e.preventDefault();
setTimeout(function () {
$('#registerform').trigger('submit');
}, 5000); // in milliseconds
});
$('#registerform').on('submit', function() {
alert('form submitted')
});