如何阻止表单重置为默认值?
我已经尝试过AJAX方式,但似乎有错误。即使我已经有了代码,但它似乎无法正常工作,控制台日志也没有显示任何错误。
这是我的表格:
<form method="post" accept-charset="utf-8" id="thisisform">
<select name="account-type">
<option value="teacher">Teacher</option>
<option value="student">Student</option>
</select> <br>
<h3>Select by:</h3>
<div id="selection">
<input type="radio" name="selection" id="byAll" value="selectAll" checked> Select All <br>
<input type="radio" name="selection" id="byVal" value="selectValue"> Select by Value <br><br>
</div>
<div id="selectNow" style="display:none;">
<select name="search-type">
<option value="username">Username</option>
<option value="firstname">First Name</option>
<option value="surname">Last Name</option>
<option value="id">ID</option>
<input type="text" name="searchVal" placeholder="Search now by the value" class="form-control"><br>
</select>
</div>
<input type="submit" value="Search and Delete" class="btn btn-primary">
</form>
这是剧本:
<script>
$('#selection').click(function() {
if($('#byVal').is(':checked')) {
$('#selectNow').slideDown("fast");
}
if($('#byAll').is(':checked')) {
$('#selectNow').slideUp("fast");
}
});
$("#thisisform").submit( function(e) {
loadAjax();
e.returnValue = false;
});
</script>
答案 0 :(得分:1)
使用e.preventDefault();
停止提交表单field1