输入字段具有浏览器记住的初始值,但我不希望它们出现

发布于 2024-12-24 19:21:19 字数 844 浏览 0 评论 0原文

我想对此输入文本字段做两件事。

<input type="text" value="[email protected]" name="Email" id="Email"
 onblur="if (this.value == '') {this.value = '[email protected]';}"
 onfocus="if (this.value == '[email protected]') {this.value = '';}" />

初始值设置为“[email protected]”,但我想仅当他们尚未在文本字段中输入内容时,才将文本颜色更改为灰色。

我还遇到的问题是,不同的浏览器具有用户在其他网站的其他输入字段中输入的单词的下拉菜单。如何清除浏览器生成的列表?

I have two things i want to do to this input text field.

<input type="text" value="[email protected]" name="Email" id="Email"
 onblur="if (this.value == '') {this.value = '[email protected]';}"
 onfocus="if (this.value == '[email protected]') {this.value = '';}" />

The initial value is set to "[email protected]" but i want to change the text color to a grey only if they have not typed in the text field.

I also have the problem of different browsers having dropdown menues of words the user has typed in other input fields on other websites. how can i clear the list the browser generates?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

聽兲甴掵 2024-12-31 19:21:19

关于自动填充,请查看 如何在 Web 表单字段/输入标记上禁用浏览器自动完成功能?

关于“水印”,我建议(如果您不反对 jQuery)占位符插件 (但是我确信如果你用谷歌搜索的话会有很多选择“ placeholder”、“watermark”和“html”(或其任意组合))

顺便说一句,我会将格式保留在一组

Regarding auto-population, have a look at How do you disable browser Autocomplete on web form field / input tag?

With regards to a "watermark", I would suggest (if you're not opposed to jQuery) placeholder plugin (However I'm sure there are a lot of options if you google "placeholder", "watermark" and "html" (or any combination thereof))

As an aside, I would keep the formatting in a set of <script> tags and leave the markup on its own. Markup should be markup; javascript should supplement that separately and not in-line with the tags)

玩心态 2024-12-31 19:21:19

如果您想要跨浏览器解决方案,可以在已有的事件处理程序中更改颜色并调用 this.style.color = "grey";,但 HTML5 包含 占位符 code> 属性,但目前还没有得到很好的支持。

为了防止事件处理程序中的代码变得难以阅读,我建议将事件处理程序放在

<script>
    document.getElementById('Email').onblur = function() {
        if (this.value == '') {
            this.value = '[email protected]';
            this.style.color = "grey";
        }
        else {
            this.style.color = "black";
        }
    };
    // etc.
</script>

要停止自动填充,请使用 (StackOverflow 答案

The color can be changed in the event handlers you already have and calling this.style.color = "grey"; if you want a cross-browser solution, but HTML5 includes the placeholder attribute, but is not well supported at this time.

To stop the code from getting hard to read in the event handlers, I suggest putting event handlers in <script>.

<script>
    document.getElementById('Email').onblur = function() {
        if (this.value == '') {
            this.value = '[email protected]';
            this.style.color = "grey";
        }
        else {
            this.style.color = "black";
        }
    };
    // etc.
</script>

To stop autofill, use <input autocomplete="off" /> (StackOverflow Answer)

心安伴我暖 2024-12-31 19:21:19
<input type="text" onblur="if(this.value==''){this.value='Enter your email address'};" onfocus="if(this.value=='Enter your email address'){this.value=''};" value="Enter your email address" size="10" alt="username" class="bt login_input" id="mod_login_username" name="username">

请参阅此网站。

http://www.mrmachinery.com/

使用 firebug

<input type="text" onblur="if(this.value==''){this.value='Enter your email address'};" onfocus="if(this.value=='Enter your email address'){this.value=''};" value="Enter your email address" size="10" alt="username" class="bt login_input" id="mod_login_username" name="username">

refer this website .

http://www.mrmachinery.com/

use firebug

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文