2011-04-24 81 views
1

我有一個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(); 
} 
?> 

回答

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> 
+0

的說插件,點擊這裏:https://github.com/mathiasbynens/Placeholder-jQuery-Plugin – Matijs 2011-04-24 09:24:07

+0

和這個:http://webcloud.se/code/jQuery-Placeholder/不錯;) – 2011-04-24 09:25:58

+0

非常感謝。這工作得很好。 – tucson 2011-04-24 10:34:24