使用Jquery提交Google自定义搜索 [英] Submit Google Custom Search with Jquery

查看:127
本文介绍了使用Jquery提交Google自定义搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google自定义搜索,我想使用自己的div与Jquery提交其表单.我没有运气就尝试了很多事情,这就是其中之一:

Im using Google custom search and I would like to submit its form using my own div with Jquery. I tried many things with no luck, this is one of them:

Google代码:

<script>
  (function() {
    var cx = 'partner-pub-2789521296837340:9402765321';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>


<gcse:search></gcse:search>

Jquery部分:

$( document ).ready(function() {

$( "div.button" ).click(function() {
  $( "form.gsc-search-box" ).submit();
    return false;
});


});

实时示例: JsFiddle

推荐答案

我们无法直接提交表单(即Google内部使用jQuery创建的表单).您必须更改代码才能更改外观.这是您要寻找的一个:

We cannot submit form (i.e., Google created internally using jQuery) directly. You have to change your code to change look and feel. Here is the one you are looking for:

<form id="cse-search-box" action="http://google.com/cse">
  <input type="hidden" name="cx" value="YOUR SEARCH ENGINE ID goes here" />
  <input type="hidden" name="ie" value="UTF-8" />
  <input type="text" name="q" size="31" />
  <input type="submit" name="sa" value="Search" />
</form>
<img src="http://www.google.com/cse/images/google_custom_search_smwide.gif">

参考: https://support.google.com/customsearch/answer/1351747?hl = zh_CN

演示场

这篇关于使用Jquery提交Google自定义搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆