我希望将 Google 自定义搜索添加到我的网站,但我已经设置了搜索框占位符的样式,我希望我的搜索框看起来像那样。
经过一番搜索,之前的问题好像都是this one已经过时了。
关于样式,我唯一发现的是:
<script>
(function() {
var cx = 'XXXXXXXXXX:YYYYYYYYY';
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
})();
</script>
<div style="width:0px;overflow:hidden;height:0px;"> <!-- if you use display:nonw here it doesn't work-->
<gcse:search></gcse:search>
</div>
<form id="searchbox_XXXXXXXXXX:YYYYYYYYY" action="">
<input value="XXXXXXXXXX:YYYYYYYYY" name="cx" type="hidden"/>
<input value="FORID:11" name="cof" type="hidden"/>
<input id="q" style="" name="q" size="75" type="text"/>
<button class="btn">Search</button>
</form>
但是,当您提交表单时,没有任何反应。
我注意到 action=""留空,当我输入我的网站“www.kokorugs.com/”时它也不起作用。
任何想法将不胜感激!
最佳答案
我发现的唯一方法是使用 JQuery 为呈现的 Google 元素创建 Hook 。由于您想将自定义搜索框挂接到元素中,因此您应该呈现 gsce:results-only 而不是 gsce:search 并遵循我之前的一个 answers 的实现.
关于javascript - 带有自定义搜索框的 Google 自定义搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15950487/