本帖最后由 领秀故湘 于 2013-2-27 10:18 编辑
在google网站定制的站内自定义搜索,因为GOOGLE强大的搜索功能和快速和全面的收录,是百度搜索无法比似的。我们可以利用它的ID来重新设置CSS样式,改造搜索输入框的颜色和样式,以及更换搜索按钮和样式等等的美化功能,以达到具有自己站内特色的真正的站内搜索!
领秀故湘网站的GOOGLE网站定制的站内搜索原始代码如下:
<div id="cse" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : 'zh-CN', style : google.loader.themes.BUBBLEGUM});
google.setOnLoadCallback(function() {
var customSearchOptions = {}; var customSearchControl = new google.search.CustomSearchControl(
'004534141474646751918:xnjsr_8zx34', customSearchOptions);
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.draw('cse');
}, true);
</script>
<style type="text/css">
.gsc-control-cse {
font-family: Arial, sans-serif;
border-color: #F9F5FF;
background-color: #F9F5FF;
}
.gsc-control-cse .gsc-table-result {
font-family: Arial, sans-serif;
}
input.gsc-input {
border-color: #DECAFF;
}
input.gsc-search-button {
border-color: #923C99;
background-color: #C78DCC;
}
.gsc-tabHeader.gsc-tabhInactive {
border-color: #DECAFF;
background-color: #DECAFF;
}
.gsc-tabHeader.gsc-tabhActive {
border-color: #C78DCC;
background-color: #C78DCC;
}
.gsc-tabsArea {
border-color: #C78DCC;
}
.gsc-webResult.gsc-result,
.gsc-results .gsc-imageResult {
border-color: #F9F5FF;
background-color: #F9F5FF;
}
.gsc-webResult.gsc-result:hover,
.gsc-imageResult:hover {
border-color: #DECAFF;
background-color: #FFFFFF;
}
.gsc-webResult.gsc-result.gsc-promotion:hover {
border-color: #DECAFF;
background-color: #FFFFFF;
}
.gs-webResult.gs-result a.gs-title:link,
.gs-webResult.gs-result a.gs-title:link b,
.gs-imageResult a.gs-title:link,
.gs-imageResult a.gs-title:link b {
color: #0066CC;
}
.gs-webResult.gs-result a.gs-title:visited,
.gs-webResult.gs-result a.gs-title:visited b,
.gs-imageResult a.gs-title:visited,
.gs-imageResult a.gs-title:visited b {
color: #0066CC;
}
.gs-webResult.gs-result a.gs-title:hover,
.gs-webResult.gs-result a.gs-title:hover b,
.gs-imageResult a.gs-title:hover,
.gs-imageResult a.gs-title:hover b {
color: #0066CC;
}
.gs-webResult.gs-result a.gs-title:active,
.gs-webResult.gs-result a.gs-title:active b,
.gs-imageResult a.gs-title:active,
.gs-imageResult a.gs-title:active b {
color: #0066CC;
}
.gsc-cursor-page {
color: #0066CC;
}
a.gsc-trailing-more-results:link {
color: #0066CC;
}
.gs-webResult .gs-snippet,
.gs-imageResult .gs-snippet,
.gs-fileFormatType {
color: #000000;
}
.gs-webResult div.gs-visibleUrl,
.gs-imageResult div.gs-visibleUrl {
color: #CC7A9F;
}
.gs-webResult div.gs-visibleUrl-short {
color: #CC7A9F;
}
.gs-webResult div.gs-visibleUrl-short {
display: none;
}
.gs-webResult div.gs-visibleUrl-long {
display: block;
}
.gs-promotion div.gs-visibleUrl-short {
display: none;
}
.gs-promotion div.gs-visibleUrl-long {
display: block;
}
.gsc-cursor-box {
border-color: #F9F5FF;
}
.gsc-results .gsc-cursor-box .gsc-cursor-page {
border-color: #DECAFF;
background-color: #F9F5FF;
color: #0066CC;
}
.gsc-results .gsc-cursor-box .gsc-cursor-current-page {
border-color: #C78DCC;
background-color: #C78DCC;
color: #0066CC;
}
.gsc-webResult.gsc-result.gsc-promotion {
border-color: #DECAFF;
background-color: #F0E9FF;
}
.gsc-completion-title {
color: #0066CC;
}
.gsc-completion-snippet {
color: #000000;
}
.gs-promotion a.gs-title:link,
.gs-promotion a.gs-title:link *,
.gs-promotion .gs-snippet a:link {
color: #0066CC;
}
.gs-promotion a.gs-title:visited,
.gs-promotion a.gs-title:visited *,
.gs-promotion .gs-snippet a:visited {
color: #0066CC;
}
.gs-promotion a.gs-title:hover,
.gs-promotion a.gs-title:hover *,
.gs-promotion .gs-snippet a:hover {
color: #0066CC;
}
.gs-promotion a.gs-title:active,
.gs-promotion a.gs-title:active *,
.gs-promotion .gs-snippet a:active {
color: #0066CC;
}
.gs-promotion .gs-snippet,
.gs-promotion .gs-title .gs-promotion-title-right,
.gs-promotion .gs-title .gs-promotion-title-right * {
color: #000000;
}
.gs-promotion .gs-visibleUrl,
.gs-promotion .gs-visibleUrl-short {
color: #CC7A9F;
}</style>
现在为了对GOOGLE自定义搜索有一个大的改观,我们只有提取出来上面那段代码的绿色部分,那是每一个网站的GOOGLE自定义ID.使用时请更换为自己的ID.改进后的代码如下:
<form id="cse-search-box" action="http://www.google.com/cse" name="cse-search-box">
<div>
<strong><input name="cx" type="hidden" value="004534141474646751918:xnjsr_8zx34" /> <input style=" width:240px; height:24px;" name="ie" type="hidden" value="UTF-8" /> <input style=
"width:250px; height:24px;text-align:center;line-height:24px;border:0; background:none;BACKGROUND-IMAGE: url(http://u.jimdo.com/www102/o/se18 ... ss.png?t=1359537129);"
name="q" size="35%" value="请输入要搜索的关键字.." onfocus="this.value=''" onblur="if(!value) {value=defaultValue;}" /> <input alt="Submit" style="border:0; background:none ;" src=
"http://u.jimdo.com/www102/o/se1898f6aca8775dc/userlayout/img/lxsea.png?t=1359536737" type="image" align="absmiddle" /></strong>
</div>
</form>
width:250px; height:24px;text-align:center;line-height:24px;border:0; background:none;BACKGROUND-IMAGE: url(http://u.jimdo.com/www102/o/se18 ... ss.png?t=1359537129);"这一句的意思 是设置搜索框的宽和高,后面是代码加一个圆角框来作背景! “
<input alt="Submit" style="border:0; background:none ;" src=
"http://u.jimdo.com/www102/o/se1898f6aca8775dc/userlayout/img/lxsea.png?t=1359536737" type="image" align="absmiddle" />”这一句是用来设置GOOGLE自定义搜索框的按钮样式,我用的是圆角背景!“
本文原创来源:http://lxgx.jimdo.com |