Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
单击google搜索按钮时的jQuery和捕获_Jquery_Search - Fatal编程技术网

单击google搜索按钮时的jQuery和捕获

单击google搜索按钮时的jQuery和捕获,jquery,search,Jquery,Search,我设置了谷歌搜索: 我正在尝试捕获单击事件的按钮是: <button class="gsc-search-button gsc-search-button-v2"><svg width="13" height="13" viewBox="0 0 13 13"><title>search</title><path d="m4.8495 7.8226c0.

我设置了谷歌搜索:

我正在尝试捕获单击事件的按钮是:

<button class="gsc-search-button gsc-search-button-v2"><svg width="13" height="13" viewBox="0 0 13 13"><title>search</title><path d="m4.8495 7.8226c0.82666 0 1.5262-0.29146 2.0985-0.87438 0.57232-0.58292 0.86378-1.2877 0.87438-2.1144 0.010599-0.82666-0.28086-1.5262-0.87438-2.0985-0.59352-0.57232-1.293-0.86378-2.0985-0.87438-0.8055-0.010599-1.5103 0.28086-2.1144 0.87438-0.60414 0.59352-0.8956 1.293-0.87438 2.0985 0.021197 0.8055 0.31266 1.5103 0.87438 2.1144 0.56172 0.60414 1.2665 0.8956 2.1144 0.87438zm4.4695 0.2115 3.681 3.6819-1.259 1.284-3.6817-3.7 0.0019784-0.69479-0.090043-0.098846c-0.87973 0.76087-1.92 1.1413-3.1207 1.1413-1.3553 0-2.5025-0.46363-3.4417-1.3909s-1.4088-2.0686-1.4088-3.4239c0-1.3553 0.4696-2.4966 1.4088-3.4239 0.9392-0.92727 2.0864-1.3969 3.4417-1.4088 1.3553-0.011889 2.4906 0.45771 3.406 1.4088 0.9154 0.95107 1.379 2.0924 1.3909 3.4239 0 1.2126-0.38043 2.2588-1.1413 3.1385l0.098834 0.090049z"></path></svg></button>
搜索
我正在尝试使用下面的jQuery,我没有得到任何错误,所以类的.gsc搜索按钮 似乎不是正确的目标。有什么想法吗

 <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
 <script>
    $(".gsc-search-button").on('click', function(event){
    alert(".gsc-search-button");
    });
 </script>

</body></html>

$(“.gsc搜索按钮”)。在('click',函数(事件){
警报(“gsc搜索按钮”);
});
如果可行,试试这些

$(()=> {  
   $(".gsc-search-button").on('click', function(event){
    alert(".gsc-search-button");
    });
});
如果上述方法无效,请尝试此方法

$(()=> {  
   $(document).on('click', ".gsc-search-button" , function(event){
        alert(".gsc-search-button");
    });
});
请使用您的代码查看工作版本


分区gsc-adBlock{
显示:无;
}
搜寻

此页面需要javascript。请启用javascript,或使用我们的
相反

    电话目录 电子邮件目录
地图 网状物 (功能(){ 变量cx='0e7979155b7270dbd'; var gcse=document.createElement('script'); gcse.type='text/javascript'; gcse.async=true; gcse.src=https://cse.google.com/cse.js?cx=“+cx; var s=document.getElementsByTagName('script')[0]; s、 parentNode.insertBefore(gcse,s); })(); $(() => { $(文档).on('单击',“.gsc搜索按钮”,函数(事件){ 警报(“gsc搜索按钮”); }); });
该代码在任何元素存在之前就在头部。此外,页面底部还加载了一个古老版本的jQuery(1.4)。它将使您的
on()
文档中抛出错误。准备就绪
,因为on()在那时不存在。嘿,查理,我将脚本移到了底部,并删除了额外的j!点击使用内部文档就绪
$(()=>{//your code})时,查询定义似乎仍然不会触发嗨,Kiran,它可以刷新页面,但当我点击那个按钮时不会触发。第二个按钮可以!谢谢你,伙计!您还可以尝试将
$(文档)
更改为按钮的最近祖先,例如:
$('body')
$('search options')
,这也是一个很好的建议,再次感谢!