http://fis.io/ajax-google-custom-search-engine.html
谷歌自定义搜索引擎
转载1.定义自己的搜索框
<div class="search">
@using (Html.BeginForm("Search", "Home", FormMethod.Get))
{
<input type="text" name="q" id="search" />
<button type="submit">搜索</button>
}
</div>
2.Search页面定义,以显示搜索结果
<div id="main">
<div id="cse" style="width: 100%;">
Loading</div>
</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', { language: 'zh-CN', "nocss": true });
google.setOnLoadCallback(function () {
var customSearchControl = new google.search.CustomSearchControl('001974288373642395983:j8fgpl2zjfu');
//通过谷歌自定义搜索(http://www.google.com/cse/)注册所对应要搜索的网站得到相应的CustomSearchControl
customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.setSearchCompleteCallback(null, function () {
$('input#search').val('@Request.QueryString["q"]').select();
$('a.gs-title').unwrap().wrap('<h3></h3>').each(function () {
var title = $(this).html().replace(/\|.*/g, '');
$(this).html(title);
});
$('b:contains("...")').contents().unwrap();
});
customSearchControl.draw('cse');
customSearchControl.execute('@Request.QueryString["q"]');
}, true);
</script>
/* Search
------------------------------------------*/
.gsc-tabsAreaInvisible, .gsc-search-box, .gsc-adBlock, .gsc-resultsHeader,
.gs-visibleUrl-short, .gs-visibleUrl-long, .gs-watermark, .gcsc-branding
{
display: none;
}
.gsc-results a
{
cursor: pointer;
}
.gsc-result-info
{
margin-bottom: 10px;
}
.gs-title
{
color: #105CB6;
}
.gs-snippet
{
margin-bottom: 5px;
color: #333;
}
.gs-snippet b
{
padding: 1px 3px;
background-color: #FEA;
}
.gsc-cursor
{
margin: 25px 0;
text-align: center;
}
.gsc-cursor-page
{
border: 1px solid #DDD;
color: #000;
margin: 0 3px;
padding: 3px 5px;
text-decoration: none;
cursor: pointer;
display: inline-block;
}
.gsc-cursor-current-page
{
background-color: #AAD069;
color: #000;
font-weight: bold;
cursor: default;
}
上一篇:Flexible theming for ASP.NET MVC
下一篇:Chirp Chirp: Visual Studio Add-In for DotLess, Js, and Css Files

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Chrome谷歌下载入口
hello,我是小索奇发现好多人说谷歌浏览器在哪里下载呀,哪里可以找到?你可能会心想,一个浏览器你还不会下载啊?还真是,有很多
chrome 软件 浏览器 搜索 谷歌浏览器 -
关于谷歌搜索的大体
谷歌免翻墙地址: 请戳我吧少用进阶搜寻语法:...
搜索 百度 hadoop -
谷歌搜索进阶(一)
@ 搜索社交媒体,如@twitter $搜索价格,如camera $400 #搜索标签,如#unitedairlines -排除,如...
搜索 社交媒体 twitter 缓存 Linux