我已经阅读了几篇帖子,包括
this和
this,但我似乎无法在提交后清除输入字段.最基本/最基本的方法是什么?
目前我有这个:
$(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(); }); });
我的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>