<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<a href="http://www.baidu.com">百度</a>
<a href="http://www.google.com">google</a>
<script type="text/javascript">
var
links = document.querySelectorAll(‘a‘)
Array.prototype.forEach.call(links, function (link) {
link.addEventListener(‘click‘, function (evt) {
evt.preventDefault()
alert(this.href)
})
})
</script>
</body>
</html>
时间: 2024-10-10 10:55:41