现在的位置: 首页 > 综合 > 正文

input标签获取焦点时清空文本框内提示信息

2014年02月02日 ⁄ 综合 ⁄ 共 709字 ⁄ 字号 评论关闭

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>input标签获取焦点时清空文本框内提示信息</title>
<script type="text/javascript">
function addLoadEvent(funct){
 var oldonload = window.onload;
 if (typeof window.onload != 'function'){
  window.onload = funct;
 }else{
  window.onload = function(){
   oldonload();
   funct();
  }
 }
}
 
 
function checkInput(){
 var inputId = document.getElementById('c_input');
 var inputDefault = '请输入搜索字符';
 function cls(){
  if (this.value == inputDefault){
   this.value = '';
  }
 }
 function res(){
  if (this.value == ''){
   this.value = inputDefault;
  }
 }
 inputId.onfocus = cls;
 inputId.onblur = res;
}
addLoadEvent (checkInput);
</script>
</head>
 
<body>
<input type="text" value="请输入搜索字符" id="c_input" />
</body>
</html>

 

【上篇】
【下篇】

抱歉!评论已关闭.