运行 ❯
获取您
的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The addEventListener() Method</h2> <p>How to pass parameter values with addEventListener().</p> <p>Click the button to perform a calculation.</p> <button id="myBtn">Try it</button> <p id="demo"></p> <script> let p1 = 5; let p2 = 7; document.getElementById("myBtn").addEventListener("click", function() { myFunction(p1, p2); }); function myFunction(a, b) { document.getElementById("demo").innerHTML = a * b; } </script> </body> </html>