btn.addEventListener('click',fn,false);怎么给fn传参数?

试过了貌似传不进去???

湖上湖
浏览 1461回答 1
1回答

万千封印

为什么这么多人踩?我觉得是个好问题啊,闭包解决之<button>click</button><script>&nbsp; &nbsp; document.querySelector("button").addEventListener("click", fn('hello world'), false);&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; function fn(a) {&nbsp; &nbsp; &nbsp; &nbsp; return function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(a);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }</script>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript