【发布时间】:2022-08-18 23:12:28
【问题描述】:
我想要按钮id 为 number1 到展示这价值的1到输入框它的 id 是question 的缩写。我还想知道我的代码是否可以变得更具可读性。
<!DOCTYPE html> <html lang=\"en\"> <head> <meta charset=\"UTF-8\"> <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> <title>Calucator</title> <style> body{ text-align: center; } </style> <script> const quest = document.getElementById(\"quest\"); const data = quest.value; const yourElement = document.createElement(\"div\"); function nums(){ const num1 = document.getElementById(\'number1\').innerText = 1; data.textContent = num1; } function run() { nums() yourElement.textContent = data quest.appendChild(yourElement); } </script> </head> <body> <h1>Calucator</h1> <input type=\"number\" placeholder=\"Enter now\" name=\"\" id=\"quest\"> <button onclick=\"run()\">=</button> <br> <button onclick=\"\" id=\"number1\">1</button> </body> </html>
标签: javascript html function onclick