在Google Custom Search中绑定单击事件以'搜索'按钮
问题描述:
我正在尝试自定义两列Google自定义搜索。我真的很喜欢通过iframe填充div(默认div#cse)的ajax。但问题在于它会推动其他内容向下突破页面。所以我想在点击'搜索'按钮时隐藏div#内容中的内容,并在'点击重置按钮'时再次显示。为了达到这个目的,我试图将点击事件处理程序绑定到提交按钮,但它没有起作用。在Google Custom Search中绑定单击事件以'搜索'按钮
$(document).ready(function(){
$("input.gsc-search-button[type=submit]").click(function(){
alert("worked");
//hide div#content
})
})
然后我试着检查它是否绑定事件。虽然它的工作不是我想要的。谷歌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
})
})
})
有没有什么办法可以做到这一点?
谢谢。
答
搜索框是在window.onload之后用google js api创建的,因此.bind()失败。解决了jquery.live()的问题。
$("input.gsc-search-button[type=submit]").live('click',showResults);
$(".gsc-clear-button").live('click', hideResults);