HTML 清除输入onclick / onfocus

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HTML 清除输入onclick / onfocus相关的知识,希望对你有一定的参考价值。

<input type="text" name="field-name-here" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'Enter Email To Get Updates':this.value;" value="Enter Email To Get Updates" />

html 点击清除输入值

<!-- Two functions to add to the input -->
<script>
// If value is blank, the value becomes the "default" value, which in this case, is "Email"
  function onBlur(el) {
    if (el.value == '') {
        el.value = el.defaultValue;
    }
}
// If you click inside the input, the default value clears, and the value becomes what is typed into the input box
function onFocus(el) {
    if (el.value == el.defaultValue) {
        el.value = '';
    }
}
</script>

<!-- Form -->
<form method="post" v65js="emailSubscribe">
    <input name="contactType" value="Newsletter" type="hidden">
    <input name="email" value="Email" type="text" onblur="onBlur(this)" onfocus="onFocus(this)">
    <button type="submit" class="defaultBtn">
        <span>Subscribe</span>
    </button>
</form>

以上是关于HTML 清除输入onclick / onfocus的主要内容,如果未能解决你的问题,请参考以下文章

清除 Select2 选择 onclick

JavaScript OnClick只能工作一次[复制]

输入的Onlock清除值

输入的Onlock清除值

清除文本框值 onclick 并显示 onblur

单击javascript onclick时,php搜索不会清除