问题
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.
回答1:
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>
来源:https://stackoverflow.com/questions/7857154/default-value-in-the-search-box-of-the-google-custom-search