JQ Web Search插件
使用
模拟的http://jp.msn.com上的效果,背景图也是链接的该站点,所以只供学习之用,不得作任何商业用途!包括开启autocomplete和关闭2种
- 开启Auto suggestion功能, 不一定要1, 任何能被判断为true的都能开启
-
关闭此功能,只要给个false就可以了
效果
Auto Suggest
搜索范围设定

代码
调用&初始化
////// add google search for each jquery objects /// ///////// override the defaults in this file /// $.fn.addGoogleSearch = function (options) { return this.each(function () { // init UI for blog initGSearch($(this)); var opts = $.extend(true, defaults, options); // init autosuggestion if (opts.isASOn) { initGSearchAutoSuggestion(); } }); }
添加Auto Suggest
var auto_suggest = function (config) {
// init the variables according to the config passed in
var $searchForm = $("#" + config.formId);
var $searchInputBox = $("#" + config.searchboxId, $searchForm);
var _apiUrl = config.api;
var _$currentSuggestion; //global current suggestion variable
var _currentQuery;
// fetch related
var _dynamicScript;
// #region Public methods
// autoSuggest functionality
// public method for AS
this.addAutoSuggest = function () {
// bind events
$searchForm.bind("submit", onSearch);
$searchInputBox.bind("keyup", onQueryBoxKeyUp);
$searchInputBox.bind("keydown", onQueryBoxKeyDown);
$searchInputBox.bind("click", onQueryBoxClick);
$searchInputBox.bind("blur", onQueryBoxBlur);
}
Jsnop获取Google数据
function fetchSuggestions() {
// add search key word and call back
var url = _apiUrl + "q=" + _currentQuery;
$.ajax({
type: 'get',
url: url,
dataType: 'jsonp',
success: eval(config.callback)
});
}
具体请看代码吧
代码下载
浙公网安备 33010602011771号