<!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>Document</title>
</head>
<body>
<form action="http://www.baidu.com">
<input type="submit" value="免费注册">
</form>
<a href="http://www.baidu.com">百度一下</a>
<script>
const form = document.querySelector('form')
//submit,提交的意思
form.addEventListener('submit',function(e){
//阻止默认行为 提交
e.preventDefault()
})
const a = document.querySelector('a')
a.addEventListener('click',function(e){
e.preventDefault()
})
</script>
</body>
</html>
08-阻止默认行为
最新推荐文章于 2024-07-18 11:48:33 发布