我有一个带有标准复位按钮的表格,因此编码:
<input type="reset" class="button standard" value="Clear" />
Run Code Online (Sandbox Code Playgroud)
麻烦的是,表示表单属于多阶段排序,因此如果用户填写一个阶段然后稍后返回,则单击"清除"按钮时,不会重置各个字段的"记住"值.
我认为附加一个jQuery函数来遍历所有字段并"手动"清除它们就可以了.我已经在表单中使用了jQuery,但我只是起步速度,所以我不知道如何解决这个问题,除了通过ID单独引用每个字段,这看起来效率不高.
TIA提供任何帮助.
我有下面的JQuery Dialog脚本,我试图找到如何在关闭对话框时触发清除表单的函数.
function clearForm()
{
$(':input','#calcQuery')
.not(':button, :submit, :reset, :hidden')
.val('');
};
// form popup
$(document).ready(function()
{
//var dataString = $("#calcQuery").serialize();
$("#formBox").dialog({
bgiframe: true,
autoOpen: false,
height: 600,
width: 400,
modal: false,
closeOnEscape: true,
title: "Calculator",
buttons: {
"Calculate": function() {
// form post
$.ajax({
type: "POST",
url: "calc.php",
data: $("#calcQuery").serialize(),
dataType: "html",
success: function(response)
{
$("#calcBox").html(response);
$("#calcBox").show();
},
error: function
(xhr, ajaxOptions, thrownError)
{
alert(xhr.status);
alert(thrownError);
}
}).responseText;
// form post
}
}
});
$('#calcButton').click(function(){
$('#formBox').dialog('open');
return false;
}); …Run Code Online (Sandbox Code Playgroud) const scriptURL = 'URL'
const form = document.forms['myform']
form.addEventListener('submit', e => {
e.preventDefault()
fetch(scriptURL, {
method: 'POST',
body: new FormData(form)
})
.then(response => console.log('Success!', response))
.catch(error => console.error('Error!', error.message))
});Run Code Online (Sandbox Code Playgroud)
<form name="myform">
<div class="col-md-6 col-sm-6">
<div class="form-group">
<label for="email" class="sr-only">Email</label>
<input name="email" class="form-control" type="email" placeholder="Email" required>
</div>
</div>
<div class="col-md-6 col-sm-6">
<button type="submit" class="btn btn-default btn-block">Subscribe</button>
</div>
</form>Run Code Online (Sandbox Code Playgroud)
处理表单提交后如何重设表单?
这是我目前正在做的事情:
form.addEventListener('submit', e => {
e.preventDefault()
fetch(scriptURL, { method: 'POST', body: new FormData(form)})
.then(response => console.log('Success!', response))
.catch(error => console.error('Error!', error.message)) …Run Code Online (Sandbox Code Playgroud)