0

我正在使用这个文本区域,以便用户可以在这里写一些文本,我正在使用onbluronfocus 所以当用户单击默认文本时它不显示,我提供一些消息作为默认值,问题是当用户写一些东西时这个文本区域比默认值也存储在数据库中,输入了其他文本,错误在哪里?我在这个变量中取值$nature_speci

 $nature_speci = trim(mysql_prep($_POST['other_naturespeci']));

这是文本区域的 html 代码

<textarea id="other_naturespeci" name="other_naturespeci" size="30" maxlength="100"  onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;">Assignment Specification in Few Words.<?php if (isset($errors)) { echo $_POST['other_naturespeci'];}elseif(isset($_GET['other_naturespeci'])){ echo $_GET['other_naturespeci'];} ?></textarea>
4

2 回答 2

0

只需使用占位符而不是 onblur 和 onfocus

<textarea id="other_naturespeci" name="other_naturespeci" size="30" maxlength="100"  placeholder="defaulttext">Assignment Specification in Few Words.<?php if (isset($errors)) { echo $_POST['other_naturespeci'];}elseif(isset($_GET['other_naturespeci'])){ echo $_GET['other_naturespeci'];} ?>
</textarea>

这就是html5的优势。看链接

于 2013-01-10T07:41:40.810 回答
0

而不是使用onblur以及onfocus为什么不使用新的 HTML5 属性placeholder。目前除 IE 之外的所有浏览器都支持它。

如果您还想在 IE 中显示它,则可以使用 javascript shim 来显示它。例如,如果您使用 jQuery,则可以使用https://github.com/parndt/jquery-html5-placeholder-shim

于 2013-01-10T07:42:11.810 回答