我有一个表单的以下 JavaScript 和 html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<!--<script src="./_js/jquery-1.7.2.min.js"></script>-->
<script>
// wait for the DOM to be loaded
$(document).ready(function() {
$("#clear_form").click(function(){
var resetForms = function () {
$('form').each(function() {
this.reset();
}); // end earch
}; // end var resetForms
resetForms();
// ************edit based on questions responses *************
var x = document.getElementById("all_clear");
x.innerHTML = '';
// *** still not working *** **
//******************** end edit based on responses *****************
});// end clear form
$("#t_form").submit(function(){
var user_input = $("#u_input").val();
$.ajax({
type: "POST",
url: "response.php",
dataType: 'json',
data: {email: user_input},
success: function(msg){
$("#all_clear").replaceWith(msg.email);
}, // end success
error: function(requestObject, error, errorThrown) {
alert(error);
alert(errorThrown);
} // end error
});// end ajax
}); // end submit
});// end ready
</script>
</head>
<body>
<form id="t_form" onsubmit="return false;">
<p>Email: <input id="u_input" type="text" value="Your email"></p>
<p id="first">Click this button when you are done.</p>
<br />
<input type="submit" name="submit" class="button" id="submit_btn" value="Send" />
<input type="submit" anme="reset" class="button" id="clear_form" value="Clear Form" />
<br />
<p id="all_clear"></p>
</form>
</body>
</html>
当我单击“清除表单”按钮时,用户输入字段会重置,但不会重置<p id="all_clear"></p>
我正在尝试重置整个表单。
进行上述更改后,编辑 仍然无法正常工作。