JavaScript中onfocus事件的用途是什么?
当元素获得焦点时触发onfocus事件。您可以尝试运行以下代码,以了解如何在JavaScript中实现onfocus 事件。
示例
<!DOCTYPE html>
<html>
<body>
<p>Write below:</p>
<input type = "text" onfocus = "newFunc(this)">
<script>
function newFunc(x) {
x.style.background = "blue";
}
</script>
</body>
</html>