<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<button id = "func1">func1</button>
<button οnclick="fn('func2')">func2</button>
<script>
let btn = document.querySelector('#func1');
//为事件传递参数:法一
btn.onclick = (function (para) {
return function (e) {
alert(para);
}
})('func1');
// 为事件传递参数:法二
function fn(a) {
alert(a);
}
//为事件传递参数:法三
function test(a) {
console.log(a)
}
let btn = document.querySelector('button');
let o = Object.create(null); let va = '123'; let btnClickFunc = test.bind(o, va); btn.addEventListener('click', btnClickFunc, false);
</script></body></html>