---
title: "文本框默认文字说明，获取焦点时消失"
author: "yl_fighting"
date: "2013-01-24T14:48:15Z"
tags: ["HTML", "JavaScript"]
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2013-01-24T14:48:49Z"
id: 1775089
url: "https://yl-fighting.iteye.com/blog/1775089"
---

**文本框默认文字说明，获取焦点时消失。**

```
<html>
<body>
	<input type="text" name="randomText" id="randomText" value="说明信息" onfocus="fo(this)" onblur="bl(this)"/>
</body>

<script>
	var text = document.getElementById("randomText").value;
	function fo(obj){
		if(obj.value == text){
			obj.value = "";
		}
	}
	
	function bl(obj){
		if(obj.value == ""){
			obj.value = text;
		}
	}
</script>
</html>
```