如何使用javascript为google自定义搜索添加价值
我想将从数据库获取的json数据添加到google自定义搜索javascript文件中,但我做不到,因为在google自定义搜索中,向输入框添加值的jquery方法失败了 需要帮忙吗 代码如下:如何使用javascript为google自定义搜索添加价值,javascript,jquery,google-custom-search,Javascript,Jquery,Google Custom Search,我想将从数据库获取的json数据添加到google自定义搜索javascript文件中,但我做不到,因为在google自定义搜索中,向输入框添加值的jquery方法失败了 需要帮忙吗 代码如下: (function() { var cx = '005172588709921972888:fsuibenly4m'; var gcse = document.createElement('script'); gcse.type = 'text/javascript';
(function() {
var cx = '005172588709921972888:fsuibenly4m';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
//checks if the id is empty
if ( $('#gsc-i-id1').is(':empty') ) {
console.log('search is empty');
//if is empty add this code
$(".gsc-input").val("Dolly Duck");
}
else {
console.log('search is not empty');
};
})();
//the above code fails because i kept on seeing "search is not empty" in log
// i tried this one and it fails again
$("#gsc-i-id1").val("Dolly Duck");
`
请提供任何帮助。在查看了cse.google.com页面的谷歌开发者参考页面后,我能够解决这个问题。 我使用?q=lady+gaga来查询特定搜索的url,使用ajax的效果非常神奇
我在cse.google.com上查看了谷歌的开发者参考页面后,解决了这个问题。 我使用?q=lady+gaga来查询特定搜索的url,使用ajax的效果非常神奇 成功了