时间:2021-09-25 08:18:15 | 栏目:JavaScript代码 | 点击:次
如下所示:
.clearFieldActive{
color:#4e4e4e;
font-weight:bold;
width:150px;
}
</style>
<script type="text/javascript">
function clearFiled(){
var bbb=document.getElementById("bbb");
if(bbb.value=="bbb"){
bbb.value='';
bbb.className='clearFieldActive';
}
}
window.document.onmousedown=function(){
var bbb=document.getElementById('bbb');
if(bbb.value==""){
bbb.value='bbb';
bbb.className='clearFieldBlurred';
}
}
</script>
</head>
<body>
<input type="text" id="aaa" value="aaa" class="clearFieldBlurred" onfocus="if(this.value=='aaa'){this.value='';this.className='clearFieldActive';}" onblur="if(this.value==''){this.value='aaa';this.className='clearFieldBlurred';}"/>
<br />
<input type="text" id="bbb" value="bbb" class="clearFieldBlurred" onclick="clearFiled()" />
</body>
</html>