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