运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <p>Use the HTML DOM to assign an "onchange" event to an input element.</p> Enter your name: <input type="text" id="fname"> <p>When you leave the input field, a function is triggered which transforms the input text to upper case.</p> <script> document.getElementById("fname").onchange = function() {myFunction()}; function myFunction() { var x = document.getElementById("fname"); x.value = x.value.toUpperCase(); } </script> </body> </html>