文本输入框默认内容实现一
结构
<input onfocus="getfocus()" onblur="outfocus()" name="username" type="text" value="输入关键字" class="txt01" />
样式
.txt01 {
color: #999999;
border: 1px solid #999999;
}
.txt02 {
color: #3366FF;
border: 1px solid #3366FF;
}
.txt03{
border:1px solid #999999;
color: #3366FF;
}
行为
<script type="text/javascript"> function getfocus() { if (username.value == '输入关键字') { username.value = ''; } username.className = 'txt02'; } function outfocus() { if (username.value == '') { username.value = '输入关键字'; username.className = 'txt01'; } else { username.className = 'txt03'; } } </script>