带有两个单选按钮的谷歌自定义搜索
google custom search with two radio buttons
这是我用于自定义搜索的代码,
<div id="cse-search-form" style="width: 100%;">Loading</div>
<script src="http://www.google.com.pk/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : 'en', style : google.loader.themes.V2_DEFAULT});
$('input[@name=sr]').change(function() {
if ($("input[@name=sr]:checked").val() == 'kw')
var qval = "kw"
else
var qval = "gw"
});
google.setOnLoadCallback(function() {
var customSearchOptions = {}; var customSearchControl = new google.search.CustomSearchControl(
'009317721292264254327:ce_olwjr2z4', customSearchOptions);
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
var qval = $("input[@name=sr]:checked").val();
var options = new google.search.DrawOptions();
options.setAutoComplete(true);
options.enableSearchboxOnly("http://www.alhudapk.com/audios/search.html", qval);
customSearchControl.draw('cse-search-form', options);
}, true);
</script>
<div style="margin-top: 10px;">
<input type="radio" name="sr" id="kw" value="kw" checked="checked" />Audio
<input type="radio" name="sr" id="gw" value="gw" / >Web
</div>
<style type="text/css">
input.gsc-input, .gsc-input-box, .gsc-input-box-hover, .gsc-input-box-focus {
border-color: #D9D9D9;
}
input.gsc-search-button, input.gsc-search-button:hover, input.gsc-search-button:focus {
border-color: #2F5BB7;
background-color: #357AE8;
background-image: none;
filter: none;
}
.gsc-search-box {
margin-top: -5px !important;
margin-bottom: -5px !important;
}
</style>
我只需要一个简单的结果,即
如果选中单选 1
search.html?kw=mysearchkeyword
如果选中 radio2?GW=MySearchKeyword
原因是对于"kw",我使用的是自己的个人搜索对于谷歌网络搜索,我需要"GW"参数来传递 URL,请帮助
我的代码在页面加载后不起作用,它只工作一次,但在页面加载后不会更改任何值
一些问题:
1)语法错误:必须input[name$=sr]
input[@name=sr]
:
2)局部变量qvar
没有意义
3) 每次单选按钮更改时必须调用options.enableSearchboxOnly
:
试试这个:
<script type="text/javascript">
google.load('search', '1', {language : 'en', style : google.loader.themes.V2_DEFAULT});
google.setOnLoadCallback(function() {
var customSearchOptions = {};
var customSearchControl = new google.search.CustomSearchControl(
'009317721292264254327:ce_olwjr2z4', customSearchOptions);
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
var options = new google.search.DrawOptions();
options.enableSearchboxOnly("http://www.alhudapk.com/audios/search.html",
$("input[name$=sr]:checked").val() );
options.setAutoComplete(true);
customSearchControl.draw('cse-search-form', options);
$('input[name$=sr]').change(function() {
options.enableSearchboxOnly("http://www.alhudapk.com/audios/search.html",
$("input[name$=sr]:checked").val() );
customSearchControl.draw('cse-search-form', options);
});
}, true);
</script>
相关文章:
- 多个单选按钮组相互干扰
- 是否可以禁用jquery中的单个单选按钮
- Javascript:无法获取变量中的单选按钮值
- 通过ajax到php文件获取单选按钮值
- 互斥单选按钮和相应的输入字段
- 用于选择MVC3中单选按钮值的JavaScript
- 如何获取单选按钮的多个实例的选定单选按钮值
- react testUtils模拟点击单选按钮而不触发onchange
- 当选择组中的单选按钮时,jQuery addClass
- Angularjs无法将单选按钮与嵌套范围内的模型绑定
- 客户端单选按钮列表验证
- Javascript:图像与单选按钮的值不匹配
- 如何在Javascript中将单选按钮值保存到cookie中
- 单击时如何更改单选按钮的CSS
- 谷歌应用程序脚本示例-如何更改单选按钮的列表框相关值
- 带有两个单选按钮的谷歌自定义搜索
- 谷歌地图-缩小时,信息窗口被关闭或其他单选按钮过滤器被“勾选”
- 谷歌分析事件跟踪代码(单选按钮)
- 谷歌表单脚本-从单选按钮获取值,目前未定义
- 使用单选按钮切换谷歌地图上的自定义图例