如题。前端页面的 input textarea 有时候须要显示默认文字以提示用户,下面为实现代码,以 input 为例。textarea 能够直接搬用


HTML

<input type="text" />

CSS

<style type="text/css">
	#content{color:#ccc; }
</style>

JavaScript

<script>		
		$("#content").focus(function(){
			if(this.value == this.defaultValue) {
				this.value='';
				$(this).css('color','#000');
			}
		});
		
		$("#content").blur(function(){
			if(this.value == '') {
				this.value=this.defaultValue;
				$(this).css('color','#ccc');
			}
		});
	});
</script>



End .

相关文章:

  • 2022-12-23
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2021-12-08
  • 2022-02-12
  • 2022-01-01
猜你喜欢
  • 2022-12-23
  • 2021-12-15
  • 2021-11-29
  • 2022-12-23
  • 2022-02-04
  • 2022-12-23
相关资源
相似解决方案