第一种 结构上阻止 :在form标签上添加 οnsubmit=“return false;” 也就是如下:
<form action="#" onsubmit="return false;">
<input type="text" name="test">
<input type="submit" value="提交">
</form>
第二种 绑定事件阻止
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>阻止默认事件</title>
</head>
<body>
<form action="#">
<input type="text" name="test">
<input type="submit" value="提交" id="csj_btn">
</form>
</body>
</html>
<script>
document.querySelector("#csj_btn").addEventListener("click",function(e){
e.preventDefault()
})
</script>