【问题标题】:Bind click event to 'search' button in Google Custom Search将点击事件绑定到 Google 自定义搜索中的“搜索”按钮
【发布时间】:2011-07-30 10:59:04
【问题描述】:

我正在尝试自定义两列 Google 自定义搜索。我真的很喜欢 iframe 上的 ajax,它填充了一个 div(默认 div#cse)。但问题是它会推动其他内容破坏页面。所以我想在单击“搜索”按钮时隐藏 div#content 中的内容,并在单击“重置按钮”时再次显示。为此,我尝试将单击事件处理程序绑定到提交按钮,但没有成功。

$(document).ready(function(){
    $("input.gsc-search-button[type=submit]").click(function(){
        alert("worked"); 
        //hide div#content
    })      
})

然后我尝试以下检查它是否绑定了事件。虽然它不是我想要的。 google api 不提供任何此类回调。

<input id="click" type="button" value="bind event"/>

$(document).ready(function(){
    $("#click").bind('click', function(){
        $("input.gsc-search-button[type=submit]").bind('click', function(){
            alert("worked");
            //hide div#content
        })          
    })
})

有什么办法可以做到吗?

谢谢。

【问题讨论】:

    标签: javascript jquery google-search google-search-api


    【解决方案1】:

    搜索框是在 window.onload 之后使用 google js api 创建的,因此 .bind() 失败。解决了 jquery.live() 的问题。

    $("input.gsc-search-button[type=submit]").live('click',showResults);
    $(".gsc-clear-button").live('click', hideResults);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-11
      • 2019-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多