2012-10-08 31 views
0

我的搜索表单在文本框中使用了一个“提示”,当对焦清除文本框和模糊时显示“提示”。检查一个文本框是否有一个“提示”值或不使用javascript

<script type="text/javascript"> 
function checkform(form) 
{ 
    if (search.s.value == "Pesquisar...") || (search.s.value == "") { 
    var term = prompt("Enter a value:"); 
    if (term) { search.s.value = term; } 
    else { return false; } 
    } 
} 
</script> 

<form id="search" method="get" action="[@siteurl]/search.php" onsubmit="return checkform(this);" > 
    <fieldset> 
    <input type="text" name="s" value="Pesquisar..." onfocus="if(this.value=='Pesquisar...') { this.value=''; }" onblur="if(this.value=='') { this.value='Pesquisar...'; }" /> 
    <input type="submit" id="searchsubmit" value="Go!" /> 
    </fieldset> 
</form> 

这是行不通的。它是搜索提示文本而不是提示。 什么错了?

回答

0
function checkform(form) 
{ 
    if (search.s.value == "Pesquisar..." || search.s.value == "")//brackets not closed properly 
    { 
     var term = prompt("Enter a value:"); 
     if (term) { search.s.value = term; } 
     else { return false; } 
    } 
} 

检查这个demo

+0

合作。谢谢。 –

+0

@LucasMatos :-) – Sibu

相关问题