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

tuc*_*son 1 javascript php

我有一个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();
}
?>
Run Code Online (Sandbox Code Playgroud)

DJa*_*ari 5

您可以在新浏览器或占位符jquery插件中使用占位符属性

<form method="get" action='index.php'>
<input type="text" name='q' SIZE="50" placeholder="search for anything here" class="hintTextbox"> 
</form>
Run Code Online (Sandbox Code Playgroud)