Ho letto diversi post, tra cui this e this, ma non riesco a ottenere il campo di input da cancellare dopo l'invio. Qual è il modo più semplice/elementare per farlo?Come resettare il campo di inserimento? jQuery
Attualmente ho questo:
$(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();
});
});
mio 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>
Una riga di codice per gestire tutti i campi '$ (FormSelector) [0] .Reset();' –