将点击事件绑定到Google自定义搜索中的“搜索"按钮 [英] Bind click event to 'search' button in Google Custom Search

查看:101
本文介绍了将点击事件绑定到Google自定义搜索中的“搜索"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自定义两列Google自定义搜索.我真的很喜欢iframe上的Ajax,它填充了一个div(默认div#cse).但是问题是,它会将其他内容下推到页面的底部.因此,我想在单击搜索"按钮时隐藏div#content中的内容,并在单击重置按钮"时再次显示.为此,我尝试了将click事件处理程序绑定到Submit按钮,但是没有用.

I am trying to customize a two column Google custom search. I really liked the ajax over iframe which populates a div (default div#cse). But the problem is it pushes the other contents down breaking the page. So I wanted to hide the contents in div#content when 'search' button is clicked and show again when 'reset button is clicked'. To achieve this i tried the to bind a click event handler to the submit button but it didn't work.

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

然后,我尝试按照以下步骤检查它是否绑定了事件.虽然它的工作不是我想要的. Google API不提供任何此类回调.

Then I tried following to check if it binds the event. Though it worked its not what I want. The google api do not provide any such callback.

<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
        })          
    })
})

有什么办法可以做到这一点?

Is there any way I can do this?

谢谢.

推荐答案

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

The search box is created with google js api after window.onload, therefore the .bind() fails. Solved the problem with jquery.live().

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

这篇关于将点击事件绑定到Google自定义搜索中的“搜索"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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