我希望我的搜索字段说“你在哪里”让它在点击时消失,然后再次出现,如果他点击外面就把它留空。
这是搜索表单:
<div id="search-10" class="widget_search">
<form role="search" method="get" id="searchform" action="http://chusmix.com/?s=" onsubmit="window.location = action + s.value + '+: <?php the_search_query() ?>'; return false;">
<div>
<input class="ubicacion" type="text" value="" name="s" id="s2" style="margin-left:0px;">
<input type="submit" id="searchsubmit" value="Buscar">
</div>
</form></div>
我尝试了这个但是由于某种原因它不起作用:
<li id="search-10" class="widget_search">
<form role="search" method="get" id="searchform" action="http://chusmix.com/">
<div>
<input class="ubicacion" type="text" value="" name="s" id="s" style="margin-left:418px;">
<input type="submit" id="searchsubmit" value="Buscar" onblur=" if(this.value== '') this.value='Where are you';" onfocus=" if(this.value=='Where are you') this.value=''; " value="Where are you" name="keyword" />
</div>
</form></li>
答案 0 :(得分:0)
答案 1 :(得分:0)
当用户点击搜索表单时,这将删除默认文本,并在用户单击搜索表单时将其添加回来。
<form id="searchform" method="get" action="search.php">
<input class="textbox" value="Search" name="s" id="s" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search';}" type="text">
<input type="submit" id="searchsubmit" value="" class="searchsubmit" />
</form>
答案 2 :(得分:-1)
请参阅以下示例了解原始javascript -
<input type="text" onblur=" if(this.value== '') this.value='Where are you';" onfocus=" if(this.value=='Where are you') this.value=''; " value="Where are you" name="keyword" />
除此之外,你可以使用jquery,dojo,mootools插件来处理这个问题。