为商业版谷歌自定义搜索框提供占位符或价值? [英] Providing placeholder or value to a commercial version of google custom search box?
本文介绍了为商业版谷歌自定义搜索框提供占位符或价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Google自定义搜索框的付费版本中输入占位符或值?
How can i enter a placeholder or value to a paid version of my Google Custom Search Box?
我试图使用提供的普通API脚本插件由Google提供如下:
I have attempted to make use of the normal API script plugin provided by Google as follows:
<h5>SEARCH ON THIS SITE</h5></h6>
<div id="cse-search-form" style="width: 100%;">Loading ...</div>
<script type="text/javascript">
google.load('search', '1', {language : 'en'});
google.setOnLoadCallback(function() {
var customSearchOptions = {};
var imageSearchOptions = {};
imageSearchOptions['layout'] = google.search.ImageSearch.LAYOUT_CLASSIC;
customSearchOptions['enableImageSearch'] = true;
customSearchOptions['imageSearchOptions'] = imageSearchOptions;
var customSearchControl = new google.search.CustomSearchControl(
'312312312313123321312231:9cjokpdtmuaey', customSearchOptions);
customSearchControl.setResultSetSize(
google.search.Search.FILTERED_CSE_RESULTSET);
var options = new google.search.DrawOptions();
options.enableSearchboxOnly("search.htm");
customSearchControl.draw('cse-search-form', options);
}, true);
</script>
我发布的代码中是否有任何明显错误?
Are there any visible errors in my posted code?
我在表格上找到了类似的问题这里但是,答案并没有解决我的问题:
I have founda similar question on the form over here but, the answer does not resolve my problem:
推荐答案
这是解决方案:
<div id="cse-search-form" style="width:100%;"></div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : 'en', style : google.loader.themes.SHINY});
google.setOnLoadCallback(function() {
var customSearchOptions = {}; var customSearchControl = new google.search.CustomSearchControl(
'XXXXXXXXXXXXXXXXXXXXX:xxxxxxxxxxx', customSearchOptions);
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
var options = new google.search.DrawOptions();
options.setSearchFormRoot('cse-search-form');
customSearchControl.draw('cse', options);
customSearchControl.setSearchCompleteCallback(this,function(){
jQuery('#main').hide();
jQuery('#cse').show();
var query = jQuery('input.gsc-input').val();
jQuery('#cse:not(.processed)').prepend('<h1 id="page-title" class="title"><span class="left">Search</span>:<span class="right"></span></h1>').addClass('processed');
jQuery('#cse .right').html(' ' + query);
});
jQuery('input.gsc-input:not(.placeholder)').val('Search').addClass('placeholder');
// Focus on search box block.
jQuery('input.gsc-input').bind('focus', function(){
if (jQuery(this).val() == 'Search'){
jQuery(this).val('');
}
}).bind('blur', function(){
if (jQuery(this).val() === ''){
jQuery(this).val('Search');
}
});
}, true);
</script>
这篇关于为商业版谷歌自定义搜索框提供占位符或价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文