js控制输入框获得和失去焦点时状态显示的方法
2015-01-30 10:51
801 查看
本文实例讲述了js控制输入框获得和失去焦点时状态显示的方法。分享给大家供大家参考。具体实现方法如下:
<!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=gb2312" /> <title>边框变色</title> <style type="text/css"> <!-- .SearchKeyword {border:1px solid #797A75;width: 202px;color: #CDCDCD;font-size:12px;} .SearchKeywordonFocus {border:1px solid #ABCD3A;width: 202px;color: #000000;font-size:12px;} --> </style> <script language="javascript"> function keywordfocus() { if (document.formSearch.keyword.value == '请输入关键字') { document.formSearch.keyword.value = ''; document.formSearch.keyword.className = 'SearchKeywordonFocus'; } } function keywordblur() { if (document.formSearch.keyword.value == '') { document.formSearch.keyword.value = '请输入关键字'; document.formSearch.keyword.className = 'SearchKeyword'; } } </SCRIPT> </head> <body> <form id="formSearch" name="formSearch" method="post" action=""> <input type="text" name="keyword" class="SearchKeyword" value="请输入关键字" onFocus="keywordfocus();" onBlur="keywordblur();" /> </form> </body> </html>
希望本文所述对大家的javascript程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- js控制输入框获得和失去焦点时状态显示的方法
- 鼠标滑入滑出,输入框获得失去焦点后触发事件的N种方法之一二
- js控制输入框取得焦点时另一内容显示/隐藏
- 在js(jquery)中获得文本框焦点和失去焦点的方法
- input 输入框获得/失去焦点时隐藏/显示文字(jquery版)
- input 输入框获得/失去焦点时隐藏/显示文字(jquery版)
- input 输入框获得/失去焦点时隐藏/显示文字(jquery版)
- input 输入框获得/失去焦点时隐藏/显示文字
- (三)在js(jquery)中获得文本框焦点和失去焦点的方法
- 文本框获得失去焦点——js和jquery方法的对比
- 在js(jquery)中获得文本框焦点和失去焦点的方法
- 在js(jquery)中获得文本框焦点和失去焦点的方法
- 输入框的提示信息(获得焦点和失去焦点时显示提示信息)
- input 输入框获得/失去焦点时隐藏/显示文字
- 在js(jquery)中获得文本框焦点和失去焦点的方法
- jq获得焦点focus,失去焦点blur,change()函数,js的onfocus,onblur,onchange()方法
- 关于输入框得到焦点时文本框清空,失去焦点时又显示默认文字,值发生改变时不再恢复默认文字的两种方法
- 总结下网上的JS控制密码框获取焦点时文字消失,失去焦点时文字出现的方法
- js和jquery 中获得文本框焦点和失去焦点的方法
- input 输入框获得/失去焦点时隐藏/显示文字