gpt4 book ai didi

html - 带有自定义搜索选择选项的搜索框

转载 作者:行者123 更新时间:2023-11-28 11:49:06 28 4
gpt4 key购买 nike

如何在一个字段中使用谷歌自定义搜索引擎的选择选项创建搜索框。我有代码,但我不知道如何组合不同类型的自定义搜索引擎以在下拉列表中选择选项:

<!DOCTYPE html>
<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8" /></head><body style="background-color:transparent; margin:3px; padding:0px;">
<form action="https://www.google.com/cse" id="cse1" target="_top" onsubmit='this["q"].value = this["sitesearch"].value + document.getElementById("searchQuery").value'>
<input type="hidden" name="q" value="" />
<input id="searchQuery" type="text" style="width:440px;" maxlength="255" value="" />
<input type="hidden" name="sitesearch" value="" /><input type="hidden" name="cx" value="00000000000000000000000:aaaaaaaaaaa" />
<span id="search-page-border">
<label class="accessibly-hidden"></label>
<label for="search-which" class="accessibly-hidden"></label><select name="" id="" style="width: auto"><option value="cse1">Google Custom Search 1</option><option value="cse2">Google Custom Search 2</option></select> </span>
<input type="submit" name="" id="" value="search" />
</form>

非常感谢

最佳答案

我在这里有一个这样的解决方案的例子:http://edu.schema-labs.appspot.com/ .You can choose the engine from the dropdown ("whole web", "curated index") and it's cx gets appended to the url.然后我从 urlparam 获取 cx 并以编程方式渲染引擎:

var init = function(cx) {
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
};

function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(window.location.search)||[,null])[1]
);
}

var cx = getURLParameter('cx') == 'null' ? cx : getURLParameter('cx');
init(cx)

关于html - 带有自定义搜索选择选项的搜索框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20379078/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com