Providing placeholder or value to a commercial version of google custom search box?

前端 未结 1 1999
北恋
北恋 2021-01-22 09:49

How can i enter a placeholder or value to a paid version of my Google Custom Search Box?

I have attempted to make use of the normal API script plugin provided by Google

相关标签:
1条回答
  • 2021-01-22 10:28

    Here is the solution:

      <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>
    
    0 讨论(0)
提交回复
热议问题