输入字段具有浏览器记住的初始值,但我不希望它们出现
我想对此输入文本字段做两件事。
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关于自动填充,请查看 如何在 Web 表单字段/输入标记上禁用浏览器自动完成功能?
关于“水印”,我建议(如果您不反对 jQuery)占位符插件 (但是我确信如果你用谷歌搜索的话会有很多选择“ placeholder”、“watermark”和“html”(或其任意组合))
顺便说一句,我会将格式保留在一组
标记中,并将标记保留在它自己的。标记就应该是标记; javascript 应单独补充,而不是与标签内嵌)
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)如果您想要跨浏览器解决方案,可以在已有的事件处理程序中更改颜色并调用
this.style.color = "grey";
,但 HTML5 包含占位符
code> 属性,但目前还没有得到很好的支持。为了防止事件处理程序中的代码变得难以阅读,我建议将事件处理程序放在
中。
要停止自动填充,请使用
(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 theplaceholder
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>
.To stop autofill, use
<input autocomplete="off" />
(StackOverflow Answer)请参阅此网站。
http://www.mrmachinery.com/
使用 firebug
refer this website .
http://www.mrmachinery.com/
use firebug