第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > JS 之 onfocus事件和onblur事件

JS 之 onfocus事件和onblur事件

时间:2023-09-13 09:03:52

相关推荐

JS 之 onfocus事件和onblur事件

在我们平时开发网站中,我们一定会经常遇到onfocus和onblur这两个事件,今天就给大家简单介绍一下这两个事件:

onfocus 事件在对象获得焦点时发生。

<html><head><script type="text/javascript">function setStyle(x){document.getElementById(x).style.background="yellow"}</script></head><body>请输入: <input type="text" οnfοcus="setStyle(this.id)" id="fname"></body></html>

当文本框得到焦点的时候,触发setStyle()方法:

onblur 事件会在对象失去焦点时发生。

<html><head><script type="text/javascript">function Msg(){var x=document.getElementById("fname").valuealert('你输入的内容是:' + x);}</script></head><body>请输入: <input type="text" id="fname" οnblur="Msg()"><br /></body></html>

当文本框失去焦点的时候,触发Msg()方法,弹出输入的内容

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。