问题
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