如何在 HTML 中當元素失去焦點時執行指令碼?
使用 onblur 屬性,在 HTML 中當元素失去焦點時執行指令碼。你可以嘗試執行以下程式碼來實現 onblur 屬性 −
示例
<!DOCTYPE html> <html> <body> <p>Type text below!</p> Country: <input type = "text" name = "myid" id = "myid" onblur = "display()"> <script> function display() { var str = document.getElementById("myid"); str.value = str.value.toUpperCase(); } </script> </body> </html>
廣告