如何设置textarea清除按钮

2025-10-31 06:51:00

1、浏览一些Blog时,会看到在留言框、搜索栏或者Email订阅栏中有一段默认的文本,比如“Type your comment here”

如何设置textarea清除按钮

2、如果你在其中点击(窗体获取焦点),这段默认的文本就会自动消失。实现这种效果非常简单: 在Header.php中添加如下脚本:<head> 

如何设置textarea清除按钮

3、//脚本要放在head标签里面 

<script type="text/javascript"> 

   function clearDefault(el) { 

if (el.defaultValue==el.value) el.value = "" 

如何设置textarea清除按钮

4、</script> 

... 

</head>

如果是输入栏(Input),在其中添加一个onfocus参数,如:<input type="text" id="input_email_address" name="email" class="input" value="Your Email Address" 

如何设置textarea清除按钮

5、onfocus="clearDefault(this)" />

如果是文本域,添加的onfocus参数如下:<textarea name="comment" id="input_comment" rows="10" class="input textarea" 

如何设置textarea清除按钮

6、onfocus="this.value=''; this.onfocus=null;" >Type your comment here</textarea>

如何设置textarea清除按钮

如何设置textarea清除按钮

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢