當元素在 HTML 中獲得使用者輸入時執行指令碼?
使用
示例
<!DOCTYPE html> <html> <body> <p>Write your name below:</p> <input type = "text" id = "myid" oninput="display()"> <p id="test"></p> <script> function display() { var p = document.getElementById("myid").value; document.getElementById("test").innerHTML = "Your answer is " + p; } </script> </body> </html>
廣告