您现在的位置: 万盛学电脑网 >> 程序编程 >> 脚本专题 >> javascript >> 正文

Javascript onFocus事件

作者:佚名    责任编辑:admin    更新时间:2022-06-22

【实例介绍】

当单击表单对象时,即将光标落在文本框或选择框时产生onFocus事件。

【实例代码】

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body>个人爱好: <form name="form1" method="post" action=""> <p>   <label>   <input type="radio" name="RadioGroup1" value="唱歌"onfocus=alert("选择唱歌!")> 唱歌</label> <br> <label> <input type="radio" name="RadioGroup1" value="跳舞"onfocus=alert("选择跳舞!")> 跳舞</label> <br> <label> <input type="radio" name="RadioGroup1" value="画画"onfocus=alert("选择画画!")> 画画</label> <br> </p> </form> </body> </html> 【代码分析】

在代码中,加粗部分代码应用了onfocus事件,选择其中的一项,弹出选择提示的对话框,
如图20.17所示。