我有一个带有标准复位按钮的表格,因此编码:
<input type="reset" class="button standard" value="Clear" />
Run Code Online (Sandbox Code Playgroud)
麻烦的是,表示表单属于多阶段排序,因此如果用户填写一个阶段然后稍后返回,则单击"清除"按钮时,不会重置各个字段的"记住"值.
我认为附加一个jQuery函数来遍历所有字段并"手动"清除它们就可以了.我已经在表单中使用了jQuery,但我只是起步速度,所以我不知道如何解决这个问题,除了通过ID单独引用每个字段,这看起来效率不高.
TIA提供任何帮助.
我已经阅读了几个帖子,包括这个,这个,但我似乎无法在提交后清除输入字段.最基本/最基本的方法是什么?
目前我有这个:
$(document).ready(function(){
$('form[name=checkListForm]').on('submit', function() {
// prevent the form from submitting
event.preventDefault();
var toAdd = $(this).find('input[name=checkListItem]').val();
$('.list').append("<div class='item'>" + toAdd + "</div>")
$('input[name=checkListItem').reset();
});
});
Run Code Online (Sandbox Code Playgroud)
我的HTML是:
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="stylesheet.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<h2>To Do</h2>
<form name="checkListForm">
<input type="text" name="checkListItem" />
<button type="submit" id="button">Add!</button>
</form>
<br/>
<div class="list"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我已将输入类型重置按钮放在窗体内,但仍然无法正常工作.
<form method='post' action='process/update_news_action.php' >
<tr>
<td colspan='2' class="col-md-4">Update News Content</td>
</tr>
<tr >
<td colspan='2' class="col-md-8"><textarea name="news" id="text"><?php echo $rows["news"] ; ?></textarea></td>
</tr>
<tr>
<td class="col-md-4"><input name='submit' type="submit" value='Publish' class="btn btn-success" /></td>
<td class="col-md-4"><input name='reset' type="reset" value='Reset' class="btn btn-primary" /></td>
</tr>
</form>
Run Code Online (Sandbox Code Playgroud)
我也试过了 <button type="reset" value="Reset">Reset</button>
我有一个小联系表格.发送邮件正在运行,但表单在提交后仍保留文本.我搜索并尝试了一些代码来清除它但没有成功.
// JavaScript Document
$('#contact-form').submit(function (e) {
"use strict";
e.preventDefault();
$.ajax({
type: "POST",
url: "contactform.php",
data: $(this).serialize(), //get form values
sucess: function (data) {
document.getElementById("contact-form").reset();
}
}).done(function (data) {
console.log(data); // will contain success or invalid
});
});
Run Code Online (Sandbox Code Playgroud)
还有一些php
<?php
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$message = $_POST["message"];
$EmailTo = "marcin@rmonline.com";
$Subject = "New Message Received";
// prepare email body text
$email_content .= "Firstname: $firstname\n";
$email_content .= "Lastname: $lastname\n";
$email_content .= "Email: $email\n"; …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) 我想重置我在表单(文本框,选择,复选框,单选按钮,......)中输入的所有值,就像我重新加载网页,但是当我触摸按钮时.
$("#button").click(function () {
//Here the code that I need
});
Run Code Online (Sandbox Code Playgroud)