1
<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;" />

像这样,如果文本字段处于焦点上但没有写任何东西,则 DefaultValue 将以较浅的颜色可见。(更像 facebook 搜索栏)...但是 id 不起作用...我写错了什么?

我不明白的另一件事是,如果我使用这个 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>

我在文本字段中调用这个脚本,如下所示:

<input type="text" name="theName" value="password" onblur="passblur()"
onfocus="passfocus()" onkeypress="passkey()" style="color:#BBB;" />

什么都没有了……我想我把一切都搞砸了!!

4

1 回答 1

1

为什么不简单地使用placeholderHTML5 属性?

<input type="text" placeholder="Default value"/>
于 2013-03-28T14:45:12.573 回答