当你浏览一些Blog时,会看到在留言框、搜索栏或者Email订阅栏中有一段默认的文本,比如“Type your comment here”,如果你在其中点击(窗体获取焦点),这段默认的文本就会自动消失。实现这种效果非常简单:
1.在Header.php中添加如下脚本:
<head>
....
//脚本要放在head标签里面
<script type="text/javascript">
function clearDefault(el) {
if (el.defaultValue==el.value) el.value = ""
}
</script>
...
</head>
2.如果是输入栏(Input),在其中添加一个onfocus参数,如:
<input type="text" id="input_email_address" name="email" class="input" value="Your Email Address"
οnfοcus="clearDefault(this)" />
3.如果是文本域,添加的onfocus参数如下:
<textarea name="comment" id="input_comment" rows="10" class="input textarea"
οnfοcus="this.value=''; this.οnfοcus=null;" >Type your comment here</textarea>