如何在文本字段的焦点上清除文本字段 [英] How to clear text field on focus of text field

查看:27
本文介绍了如何在文本字段的焦点上清除文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户点击时清除文本字段

I want to clear the text field when the user clicks on that

推荐答案

为此,您需要使用脚本语言,可能是 javascript.这里是一个例子

To do this you will need to use a scripting language, probably javascript. Here an example

<input type='text' value'Some text' onclick='javascript: this.value = ""' />

希望这会有所帮助.

为了满足大卫在这里解释的第二个例子,以防你正在寻找什么

To meet what David is explain here is a second example in case that is what you are looking for

<script type='javascript'>
    var clear = true;
    function clear(obj)
    {
        if(clear)
        {
            obj.value = '';
            clear = false;
        }
    }
</script>

<input type='text' value'Some text' onfocus='clear(this);' />

这篇关于如何在文本字段的焦点上清除文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆