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

atu*_*tul 4 jquery placeholder search-box google-custom-search

我使用以下代码添加了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);
})();
Run Code Online (Sandbox Code Playgroud)

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

我也尝试过代码

$('input.gsc-input').attr('placeholder', 'custom text here');
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

suk*_*tup 6

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

(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';
};
Run Code Online (Sandbox Code Playgroud)