怎么把事件click和button绑定啊
<!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>
<h1 id="id1">My Heading 1</h1>
<p> <button οnclick="test()">点击这里!</button></p>
<!-- <script type="text/javascript">
var temp = 'red';
function test() {
if (temp === 'red') {
document.getElementById('id1').style.color = 'blue';
temp = 'blue';
} else (temp === 'blue') {
document.getElementById('id1').style.color = 'red';
temp = 'red';
}
}
</script> -->
<script>
var i = 1;
function test() {
i++;
if (i % 2 == 0) {
document.getElementById('id1').style.color = 'blue';
} else {
document.getElementById('id1').style.color = 'red';
}
}
</script>
</body>
</html>