Google自定义搜索的搜索框中的默认值 [英] Default Value in the Search Box of the Google Custom Search

查看:112
本文介绍了Google自定义搜索的搜索框中的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google自定义搜索的标准复制和粘贴代码(免费提供广告)。我想在加载页面的时候在搜索字段中添加一些文本可能吗?



如果是这样,怎么做?



以下是代码:

 < div id =csestyle =width:100%;>> ;装载和LT; / DIV> 
< script src =// www.google.com/jsapitype =text / javascript>< / script>
< script type =text / javascript>
google.load('search','1',{language:'en'});
google.setOnLoadCallback(function(){
var customSearchControl = new google.search.CustomSearchControl('000203232594935527974:aspio6dmwkq');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.draw('cse');
},true);
< / script>
< link rel =stylesheethref =// www.google.com/cse/style/look/default.csstype =text / css/>

漂浮的默认Google徽标和单词Custom Search不会打扰我。



我也想知道我是否也可以在页面加载时运行自定义搜索。

使用仅限结果代码。通过这样做,您可以使用自己的搜索框。



如果您希望某些文本显示在搜索字段中,请尝试以下操作:

 < form id =cse-search-boxaction =http://www.yoursite.com/method =get> 


< / form>


I am using the standard copy and paste code for the Google Custom Search (free with ads). I want to have some text in the search field when the page is loaded is that possible?

If so, how?

Here's the code:

<div id="cse" style="width: 100%;">Loading</div>
<script src="//www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
  google.load('search', '1', {language : 'en'});
  google.setOnLoadCallback(function() {
    var customSearchControl = new google.search.CustomSearchControl('000203232594935527974:aspio6dmwkq');
    customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
    customSearchControl.draw('cse');
  }, true);
</script>
<link rel="stylesheet" href="//www.google.com/cse/style/look/default.css" type="text/css" />

The floating default Google logo and words "Custom Search" don't bother me.

I was also wondering if I could run the custom search on page load as well.

解决方案

Use the "results only" code. By doing so, you can use your own search box.

If you want some text to show up in the search field, try this:

<form id="cse-search-box" action="http://www.yoursite.com/" method="get">

<input type="text" name="q" autocomplete="off" size="30" onfocus="if(this.value==this.defaultValue)value=''" onblur="if(this.value=='')value=this.defaultValue;" value="THE TEXT YOU WANT HERE" /> 

</form>

这篇关于Google自定义搜索的搜索框中的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆