Przeczytałem kilka postów, w tym this i this, ale nie mogę uzyskać pola wejściowego do wyczyszczenia po przesłaniu. Jaki jest najbardziej podstawowy/elementarny sposób na zrobienie tego?Jak zresetować pole wejściowe? jQuery
Obecnie mam to:
$(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();
});
});
Moje HTML jest:
<!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>
jednej linii kodu do obsługi wszystkich polach '$ (formselector) [0] .reset();' –