效果:
- 只调用一个input,不用切换
- 没用jq,原生js
demo:
- ↑本站顶部 - 输入搜索词后, 按回车键是wordpress自带搜索, 点GOOGLE是用Google搜索
- 或在此测试:
大发说z叔那儿就是这个效果, 好久没去大叔那儿了都忘了,一看还真是的,是就是吧反正我写的不一样
上代码
<input id="xhd_sform" onkeyup="aa(this)" value="" type="text" placeholder="Hit Enter to search…" />
<script>
/**
* Merger_wp_ggsearch
* coder: xiaohudie
* 2013-06-08
*/
function aa(obj){
document.getElementById("xhd_f1").value=obj.value;
document.getElementById("xhd_f2").value=obj.value;
}
document.onkeydown = function(evt){
var evt = window.event?window.event:evt;
if(evt.keyCode==13)
{
document.getElementById("top_search_form").submit();
}
}
function xhd_smt(){
document.getElementById("top_search_form2").submit();
}
</script>
<form style="display:none" accept-charset="UTF-8" action="http://xiaohudie.net" name="s" id="top_search_form" method="get">
<input type="text" name="s" id="xhd_f2" placeholder="Hit Enter to search…" >
</form>
<form style="display:none" accept-charset="UTF-8" action="http://xiaohudie.net/search" id="top_search_form2" method="get">
<input type="text" name="q" id="xhd_f1" value="" placeholder="Search in Google" tabindex="1" autocapitalize="off" autocomplete="off" >
<input type="submit" value="Google" tabindex="1" autocapitalize="off" autocomplete="off">
</form>
<input type="button" id="xhd_gs" onClick="javascript:xhd_smt();" value="GOOGLE ">
merger_wp_ggsearch is coded by http://xiaohudie.net. Any posts here is one hundred percent original, so please keep my link so as not to hurt this pretty girl. -
好东西
按了google,貌似没有结果,失效了?
@这样 没有失效呀,你是手机输入的?
来瞻仰女大神~嘿嘿