如何在单击 href
元素时删除表单内的所有输入字段?
<script type="text/javascript">
$('.delete-link').on('click', function() {
//remove all input inside #form-delete
});
</script>
<form id="form-delete" action="/post>" method="post">
<input type="text" name="test1" value="">
<textarea name="test2" rows="8" cols="80">TEST</textarea>
<input type="checkbox" name="test3" value="">
<input type="number" name="test4" value="">
<input type="password" name="test5" value="">
<input type="email" name="test5" value="">
</form>
<a href="#" class="delete-link">
<span>Remove All input</span>
</a>
$("#form-delete").find("input").remove();
- Tyler Roper<input>
元素。如果你也想删除<textarea>
,那么你可以这样做:$("#form-delete").find("input,textarea").remove();
- Tyler Roper$("#form-delete").find("input,select,textarea").remove();
。 - Arun P Johny