<!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> <title>onfocus与OnBlur的例子</title> <script type="text/javascript"> //默认值为请输入职位或企业名 function ShowInfo() { var oDiv = document.getElementById("Text1"); //当失焦的时候如果没有填制,还是获取默认值,如果填了值给个背景 if (oDiv.value == "") { oDiv.value = "请输入职位或企业名"; } else { oDiv.style.borderColor = "black"; } } </script> </head> <body> <input id="Text1" type="text" value="请输入职位或企业名" onfocus="this.value='';" onblur="ShowInfo();" /> </body> </html>
OnFocus与OnBlur的例子
最新推荐文章于 2025-06-06 09:17:29 发布
本文提供了一个使用onfocus与onblur事件的简单示例,通过JavaScript实现输入框聚焦与失焦的效果,当输入框失去焦点且为空时,将显示默认提示文字;反之则更改边框颜色。
482

被折叠的 条评论
为什么被折叠?



