在我的html网站的谷歌自定义搜索引擎中添加占位符到文本框

我使用以下代码添加了Google自定义搜索引擎。

(function() { var cx = '005899633628958982661:wekn1lpckzg'; 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); })(); 

现在我的网站有一个可用的搜索框,唯一的问题是我无法在搜索文本框中使用占位符。

我也尝试了代码

 $('input.gsc-input').attr('placeholder', 'custom text here'); 

但它不起作用。

我使用以下代码,它对我有用!

 (function() { var cx = '!!!!!!!!!!!!!!!!!!!'; 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); })(); window.onload = function(){ document.getElementById('gsc-i-id1').placeholder = 'SEARCH'; }; 

这个对我有用:

 window.onload = demo; function demo() { document.getElementById("gsc-i-id1").setAttribute("placeholder", "SEARCH") }