谷歌自定义搜索参考部门

Google Custom Search Reference Div

本文关键字:参考部 搜索 自定义 谷歌      更新时间:2024-05-07

设置Google自定义搜索:https://www.google.com/cse/

我希望能够使用JS来调用用户键入的搜索项。

    <script>
    (function () {
        var cx = 'mygoogle-gcse-id';
        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>

如何使用JS调用在搜索表单中输入的元素?

我想打电话给:

onblur="somefunction('gsce-input-data')";

当上面的代码加载脚本时,会动态创建搜索元素。这意味着您需要使用"live"方法连接侦听器,以便在元素实际进入DOM:时连接它们

  $('.gsc-input').live('blur', function(e) { //do something });

下面是小提琴的例子:http://jsfiddle.net/pASWm/1/