myform 是form的id属性值
1.调用reset()方法
转自https://www.cnblogs.com/ljblog/p/7735422.html
myform 是form的id属性值
1.调用reset()方法
function fomrReset()
{
document.getElementById("myform").reset();
}
2. 逐个清空input、select值
function resetAll() {
$("#myform").find('input[type=text],select,input[type=hidden]').each(function() {
$(this).val('');
});
}
3.排除法清空form表单
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>form表单重置</title>
<script src="login/js/jquery-1.4.2.min.js"></script>
</head>
<body>
<form action="" method="post" id="myform">
<label for="name">姓名:</label>
<input type="text" name="name" id="name" value="" placeholder="请输入名字" /
<label>性别:</label>
<input type="radio" name="sex" checked value="" />男
<input type="radio" name="sex" value="" />女
</form>
<input type="button" name="" value="重置" οnclick="formReset()" />
<script type="text/javascript">
function formReset() {
$(':input', '#myform')
.not(':button, :submit, :reset, :hidden,:radio') // 去除不需要重置的input类型
.val('')
.removeAttr('checked')
.removeAttr('selected');
}
</script>
</body>
</html>