Google自定义搜索引擎使用以下标记打印搜索表单:
<gcse:search></gcse:search>
打印后,搜索表单的文本输入为:
<input id="gsc-i-id1" class="gsc-input" type="text" lang="es" autocomplete="off" size="10" name="search" title="buscar" style="width: 100%; padding: 0px; border: medium none; margin: 0px; height: auto; outline: medium none; background: rgb(255, 255, 255) url("https://www.google.com/cse/static/es/google_custom_search_watermark.gif") no-repeat scroll left center;" x-webkit-speech="" x-webkit-grammar="builtin:search" dir="ltr" spellcheck="false">
我正在尝试为文本输入获得焦点或点击它时创建一个事件,如下所示:
$( "#gsc-i-id1" ).click(function() {
alert( "test" );
});
但它不起作用。我的想法已经不多了。由于我们正在处理组件标签这一事实,jQuery无法正常工作吗?我怎样才能完成我想做的事情?
答案 0 :(得分:1)
您需要将event
委托给某些ancestor
或body
,如下所示:
$("body").on('click focus','#gsc-i-id1',function() {
alert( "test" );
});