1.form表单重置
myform 是form的id属性值
1.调用reset()方法
function fomrReset()
{
document.getElementById("myform").reset();
}
2.jquery中form表单序列化
serialize() 方法通过序列化表单值,创建 URL 编码文本字符串。
可以选择一个或多个表单元素(比如 input 及/或 文本框),或者 form 元素本身。
序列化的值可在生成 AJAX 请求时用于 URL 查询字符串中。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
</head>
<body>
<form action="" id="form1">
<input type="text" id="t1" name="name">
<input type="text" id="t2" name="pwd">
<button> 提交</button>
</form>
<script>
$('button').click((e) => {
e.preventDefault();
console.log($('#form1').serialize());
})
</script>
</body>
</html>