<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<!--第一种禁用方法,给一个onsubmit事件禁用-->
<form action="login.php" method="post" id="login" onsubmit="return false">
<label class="title">用户登录</label>
<label for="email">邮箱:</label>
<input type="email" id="email" name="email" value="" autofocus />
<label for="password">密码:</label>
<input type="password" id="password" name="password" />
<!-- 第二种禁用方法将button的submit值改为button -->
<button name="submit" type="button">登录</button>
</form>
<ul id="ul_id">
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
<li>item5</li>
</ul>
<script>
document.forms.login.submit.onclick = function (ev) {
// 禁用默认提交行为
ev.preventDefault();
}
ul_id.addEventListener("click",(e)=>{
console.log(e.target) // 指向触发事件的元素
console.log(e.currentTarget) // 绑定事件的元素
})
</script>
</body>
</html>