输入带有水印提示和提交值的文本框

时间:2011-04-24 09:07:41

标签: php javascript

我有一个html输入框,用于输入用于运行PHP脚本的值。 也可以使用URL和GET传递该值。

现在我想在我的文本框中添加水印提示。 我使用了这位先生的代码: http://www.drewnoakes.com/code/javascript/hintTextbox.html

它工作正常,但如果我输入一个值并提交文本框不会显示值,而是默认提示。我希望看到价值。 我怎么能这样做?

以下是部分代码:

<form method="get" action='index.php'>
<input type="text" name='q' SIZE="50" value="search for anything here" class="hintTextbox"> 
</form>

<?php
$Input = "";
if (isset($_GET['q'])) $Input = $_GET['q'];

try {
    script($Input);
}
catch (Exception $e) {
    print $e->getMessage();
}
?>

1 个答案:

答案 0 :(得分:5)

您可以在新浏览器或placeholder jquery plugin

中使用占位符属性
<form method="get" action='index.php'>
<input type="text" name='q' SIZE="50" placeholder="search for anything here" class="hintTextbox"> 
</form>