Custom search engine Button click

这一生的挚爱 提交于 2019-12-11 18:27:28

问题


Im trying to call function on Custom Search Engine search button click.

Code at the moment i try is:

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

Doesnt work.

Site: http://akcijos.igloro.info/?q=Android

EDIT:

Found solution on post: Bind click event to 'search' button in Google Custom Search


回答1:


Found solution of this on other stackoverflow post.

Reason:

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

Code:

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

Other post url: Bind click event to 'search' button in Google Custom Search




回答2:


Are you trying to override the default action of pressing the button? You could try doing this:

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


来源:https://stackoverflow.com/questions/12673963/custom-search-engine-button-click

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!