在 HTML 中,当元素失去焦点时执行脚本?
htmlweb developmentfront end technology更新于 2025/8/16 16:12:17
使用 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>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

