【发布时间】:2015-01-15 16:35:49
【问题描述】:
我正在用 PHP 构建一个表单,并且我有一个目前可以正常工作的字段,如下所示:
<input type='text' name='Name' value='Name'/>
但我不希望用户必须手动删除该值,所以我这样做了:
<input type='text' name='Name' value='Name'
onblur="if(this.value==''){ this.value='Name'; this.style.color='#BBB';}"
onfocus="if(this.value=='Name'){ this.value=''; this.style.color='#000';}"
style="color:#BBB;" />
但很明显,因为这是在 PHP 中,并且表单以 $output="<form... 开头,所以它不起作用并且由于 " 而出现错误
于是我创建了这个:
<input type='text' name='Name' value='Name'
onblur='if(this.value==''){ this.value='Name'; this.style.color='#BBB';)'
onfocus='if(this.value=='Name'){ this.value=''; this.style.color='#000';}'
style='color:#BBB' />
这不会通过错误,但根本不起作用。我的意思是表单正确显示,但点击后该值不会消失。所以我想将onblur和onfocus中的'更改为",这在html中有效,但在php中出现了与以前相同的错误。那么解决这个问题的方法是什么?
【问题讨论】:
-
您从
'开始 onblur,然后在其中使用'。如果你这样做,而不是简单地使用点击事件或函数,那么你需要转义你的引号。在谷歌搜索会解释你如何。