我覺得這是我的職能問題消失。基本上,當我點擊搜索欄時,我不得不刪除文本「搜索...」,而不是能夠輸入它。佔位符「搜索...」不是當我運行當前的代碼
\t
function active(){
\t \t var searchBar = document.getElementById('searchBar');
\t \t if(searchBar.value == 'Search...')
{
\t \t \t searchBar.value = '';
\t \t \t searchBar.placeholder = 'Search...';
\t \t }
\t }
\t function inactive(){
\t \t var searchBar = document.getElementById('searchBar');
\t \t if(searchBar.value == '')
{
\t \t \t searchBar.value = 'Search...';
\t \t \t searchBar.placeholder = '';
}
}
\t <form action="search.php" method="post">
\t \t <input type="text" id="searchBar" placeholder="" value="Search..." maxlength="30" autocomplete="on" onMouseDown="active();" onBlur="inactive();"/><input type="submit" id="searchBtn" value="Go!" />
\t </form>
爲什麼你使用'value'而不是'placeholder'?這就是爲什麼我們有'placeholder'爲... – Dekel
我不知道那個好,並基於這一關我在網上找到的HTML代碼。如果我擺脫了價值,並將該文本插入佔位符,我會好嗎? – Nate
只需使用'placeholder'屬性... – Li357