原型表单字段文本值在焦点上消失
我目前正在使用:
<input type="text" value="username" onfocus="this.value=''" name="login" id="login">
在我网站上的登录表单字段中,该字段使用“用户名”一词填充表单,直到用户单击该字段,然后清除该字段。
问题是,如果用户单击该字段,输入一些内容,单击离开,然后单击返回,则会清除他们输入的所有内容!
我已经在我的网站上使用原型,所以我想知道是否有一种方法,使用原型,我可以让第一个“onfocus”清除该字段,但此后再也不会。
这有道理吗?我在谷歌搜索任何资源时遇到困难,有人可以指出我正确的方向吗?
我尝试过:
<input type="text" value="username" onfocus="if (this.value = 'username') this.value = ''" name="login" id="login">
但似乎不起作用
I am currently using:
<input type="text" value="username" onfocus="this.value=''" name="login" id="login">
on my sign in form field on my site, which populates the form with the word "username" until the user clicks on the field, which is then cleared.
The problem is, if the user clicks on the field, types something in, clicks away, and clicks back, it clears whatever they have typed!
I am already using prototype on my site so I was wondering if there was a way, using prototype, I could just have the very first "onfocus" clear the field, but never again after that.
Does this make sense? I am having trouble googling any resources, can someone point me in the right direction?
I tried:
<input type="text" value="username" onfocus="if (this.value = 'username') this.value = ''" name="login" id="login">
and it doesn't seem to be working
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅有条件地清除它:
if (this.value == 'username') this.value = ''
Only conditionally clear it:
if (this.value == 'username') this.value = ''