我試圖使用JavaScript創建一個文本框的水印,但與當前的代碼中,我得到一個錯誤添加JavaScript文字水印不工作
網頁錯誤的詳細信息 消息:「searchInput」是不確定的
<script type="text/javascript" language="javascript">
function watermark(inputId,text){
var inputBox = document.getElementById(searchInput);
if (inputBox.value.length > 0){
if (inputBox.value == text)
inputBox.value = '';
}
else
inputBox.value = text;
}
</script>
<input name="keyword2" id="searchInput" type="text" class="searchbox2"
value="Enter a State, County, City or Zip" size="77" maxlength="30"
onfocus="watermark('searchInput','Enter a State, County, City or Zip');"
onblur="watermark('searchInput','Enter a State, County, City or Zip');"/>
會如此好看,如果所有瀏覽器都支持html5佔位符屬性 – Muleskinner