0

我的搜索表单在文本框上使用“提示”,当聚焦时它会清除文本框并在模糊时显示“提示”。

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

这是行不通的。它正在搜索提示文本而不是提示。怎么了?

4

1 回答 1

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; }
   }
}

检查这个演示

于 2012-10-08T06:02:19.797 回答