运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h2>JavaScript addEventListener()</h2> <p>This example demonstrates how to pass parameter values when using the addEventListener() method.</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>