[英]Password int on Textfield - NO jQuery/CSS3/HTML5
<input type="text" name="theName" value="password"
onblur="if(this.value == ''){ this.value = 'password'; this.style.color = '#333'; this.type="text";}"
onfocus="if(this.value == 'password'){ this.style.color = '#666';}"
onkeypress="if(this.value == 'password'){ this.value = ''; this.style.color = '#000';this.type="password";}"
style="color:#BBB;" />
Like this, if the textfield is onfocus but not a thing is been written on it, the DefaultValue will be visible with a lighter color. 这样,如果文本字段处于焦点上,但未在其上写入任何内容,则将以较浅的颜色显示DefaultValue。 (more like the facebook search bar)... But id doesn't work... What did i write wrong? (更像是Facebook搜索栏)...但是id无效...我写错了什么?
Another thing that i don't get is that if i take this javascript and i put it into a tag like this: 我没有得到的另一件事是,如果我使用此javascript并将其放入这样的标记中:
<script type="text/javascript">
function passfocus(){
if(this.value == 'password'){this.style.color = '#666';}}
function passblur(){
if(this.value == 'password'){ this.style.color = '#666';}}
function passkey(){
if(this.value == 'password'){
this.value = ''; this.style.color = '#000';this.type="password";}}
</script>
And i call this scripts in the textfield like this: 我在文本字段中这样称呼这些脚本:
<input type="text" name="theName" value="password" onblur="passblur()"
onfocus="passfocus()" onkeypress="passkey()" style="color:#BBB;" />
Nothing works anymore... I think i kinda messed everything up!! 什么都没有了...我想我有点搞砸了!
为什么不简单地使用placeholder
HTML5属性?
<input type="text" placeholder="Default value"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.