我正在使用CSE(谷歌自定义搜索)来显示结果,但它会显示默认的10个结果,我想按控制数量显示结果,例如显示4个结果。这是我的代码。

 function gcseCallback() {
    // key to search
    var key = $("#txtkeyword").val();
    if (document.readyState != 'complete')
        return google.setOnLoadCallback(gcseCallback, true);
    google.search.cse.element.render({ webSearchResultSetSize: 'small', gname: 'gsearch', div: 'google-search', tag: 'searchresults-only', attributes: { linkTarget: '_blank' } });
    var element = google.search.cse.element.getElement('gsearch');
    element.execute(key);
};
(function () {
    var cx = 'xxxxx:xxxx';
    var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
    gcse.src = (document.location.protocol == 'https' ? 'https:' : 'https:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
})();

最佳答案

https://www.google.com/cse/search/advanced

网页搜索限制->结果大小(0-20)

10-02 14:09