输入类型文本中的背景文本 php

Background text in input type text php

我认为这是一个简单的问题,但我不知道如何在 google

中搜索此问题

我需要输入文本字段中的背景文本。喜欢:插入你的名字。当我按下该字段以插入我的名字时,文本消失了

现在这是我的代码..

<textarea id="dox" name="<?php echo $_SESSION["dox"]; ?>" rows="25" cols="80">hello type here.</textarea><br />

谁能帮帮我?添加所需的一切...非常感谢 <3

您需要占位符属性:

<textarea id="dox" name="<?php echo $_SESSION["dox"]; ?>" rows="25" cols="80" placeholder="hello type here."></textarea>

对于文本区域和输入字段,您可以像这样简单地使用 "placeholder" 属性:

<textarea placeholder="hello type here." id="dox" name="<?php echo $_SESSION["dox"]; ?>" rows="25" cols="80"></textarea>

但是,此属性并不与所有(主要是旧的)浏览器兼容。 如果您想访问这些浏览器,您可以使用 JQuery 插件,例如:https://github.com/mathiasbynens/jquery-placeholder

或者像这样将 javascript 与 onfocus 和 onblur 事件一起使用:

<textarea onfocus="if(this.value=='Placeholder text')this.value='';" onblur="if(this.value=='')this.value='Placeholder text';">Placeholder text</textarea>