我想在我的搜索表单中添加一个对用户不可见的值,这样当他们寻找披萨时,他们实际上是在搜索:#pizza#
我使用的是wordpress,我在搜索表单中使用了下面的代码。
<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">
</div>
</form>
</li>发布于 2010-12-11 10:33:04
这应该是可行的:
JavaScript
function wrapSearch() {
var text = document.getElementById('s');
text.value = "#" +text.value+ "#";
}HTML将onsubmit="wrapSearch()"添加到form标记
<li id="search-10" class="widget_search"><form role="search" method="get" id="searchform" action="http://chusmix.com/" onsubmit="wrapSearch()">
<div>
<input class="ubicacion" type="text" value="" name="s" id="s" style="margin-left:418px;">
<input type="submit" id="searchsubmit" value="Buscar" >
</div>
</form>
</li>发布于 2010-12-11 10:21:36
<script>
function searchValue(val)
{
if(val.value!='')
{
val.value = "#"+val.value+"#";
return true;
}
else
{
return false;
}
}
</script>
<input type="submit" id="searchsubmit" value="Buscar" onclick="return searchValue(document.getElementById('s'));">发布于 2010-12-11 10:18:52
使用jQuery
$('#source').change(function() {
$('#target').val("#"+$(this).val()+"#")
});https://stackoverflow.com/questions/4414829
复制相似问题