【问题标题】:Custom search engine Button click自定义搜索引擎按钮点击
【发布时间】:2012-10-01 21:41:30
【问题描述】:

我试图在自定义搜索引擎搜索按钮点击时调用函数。

我现在尝试的代码是:

<script type="text/javascript">
$(".gsc-search-button input[type=button]").click(function()
{
  alert("1");
});
</script>

没有用。

网站:http://akcijos.igloro.info/?q=Android

编辑:

在帖子中找到解决方案:Bind click event to 'search' button in Google Custom Search

【问题讨论】:

    标签: jquery click


    【解决方案1】:

    在其他 stackoverflow 帖子上找到了解决方案。

    原因:

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

    代码:

    <script type="text/javascript">
    $("input.gsc-search-button[type=submit]").live('click', function()
    {
      console.log("clicked");
      alert("1");
    });
    </script>
    

    其他帖子网址:Bind click event to 'search' button in Google Custom Search

    【讨论】:

    • 没错!没想到 ;) - 感谢您将我带到正确的位置。
    • 从 jQuery 1.7 开始,不推荐使用 .live() 方法。使用 .on() 附加事件处理程序。
    【解决方案2】:

    您是否试图覆盖按下按钮的默认操作?您可以尝试这样做:

    $(".gsc-search-button input[type=button]").click(
        function(e)
        {
            e.preventDefault();
            alert("1");
        }
    );
    

    【讨论】:

    • 没有。不覆盖。只是调用其他应该将查询值写入数据库的函数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多