我将 Google 和 Wikipedia 搜索框添加到页面中,并且我正在寻找一种方法来根据所选单选按钮更改建议。
事实上,建议语言应该根据检查的语言而改变。
这是我的实际代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Google Suggest Test</title>
<script type="text/javascript" src="googlesuggest.js"></script>
</head>
<body>
<form action="http://www.google.com/search" id="google_suggest" >
<div>
<input name="q" value="" type="text" />
<input type="submit" value="OK" />
<input type="hidden" name="complete" value="1" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="hidden" name="oe" value="UTF-8" />
<input type="hidden" name="num" value="30" />
<input type="hidden" name="channel" value="s" />
<br />
<label for="all"><input id="all" type="radio" name="lr" value="" checked="checked" />All</label>
<label for="lang_en"><input id="lang_en" type="radio" name="lr" value="lang_en" />English</label>
<label for="lang_fr"><input id="lang_fr" type="radio" name="lr" value="lang_fr" />French</label>
<label for="lang_de"><input id="lang_de" type="radio" name="lr" value="lang_de" />German</label>
<label for="lang_ru"><input id="lang_ru" type="radio" name="lr" value="lang_ru" />Russian</label>
<label for="lang_es"><input id="lang_es" type="radio" name="lr" value="lang_es" />Spanish</label>
<br /><br />
</div>
</form>
<form method="post" action="wikipedia_action.php">
<div>
<input type="text" name="wikipedia_field" />
<input type="submit" value="OK" />
<br />
<label for="wik_en"><input type="radio" checked="checked" name="wikipedia" id="wik_en" value="wik_en" />English</label>
<label for="wik_fr"><input type="radio" name="wikipedia" id="wik_fr" value="wik_fr" />French</label>
<label for="wik_de"><input type="radio" name="wikipedia" id="wik_de" value="wik_de" />German</label>
<label for="wik_ru"><input type="radio" name="wikipedia" id="wik_ru" value="wik_ru" />Russian</label>
<label for="wik_es"><input type="radio" name="wikipedia" id="wik_es" value="wik_es" />Spanish</label>
</div>
</form>
</body>
</html>
脚本 googlesuggest.js:
$(document).ready(function(){
window.google = {
kEI: "wR-4SfmNIMyA-AbluKj5Cg",
kEXPI: "17259,17291,18169",
kHL: "fr"
};
var _gjwl = location;
function _gjuc() {
var a = _gjwl.hash.substring(1);
if (/(^|&)q=/.test(a) && a.indexOf("#") == -1 && !/(^|&)cad=h($|&)/.test(a)) {
_gjwl.replace("search?" + a.replace(/(^|&)fp=[^&]*/g, "") + "&cad=h");
return 1
}
return 0
};
window._gjuc && location.hash && _gjuc();
google.y = {};
google.x = function(e, g) {
google.y[e.id] = [e, g];
return false
};
window.clk = function(b, c, d, e, f, g, h) {
if (document.images) {
var a = encodeURIComponent || escape;
(new Image).src = ["/url?sa=T", c ? "&oi=" + a(c) : "", d ? "&cad=" + a(d) : "", "&ct=", a(e), "&cd=", a(f), b ? "&url=" + a(b.replace(/#.*/, "")).replace(/\+/g, "%2B") : "", "&ei=wR-4SfmNIMyA-AbluKj5Cg", g].join("")
}
return true
};
window.gbar = {
qs: function() {},
tg: function(e) {
var o = {
id: 'gbar'
};
for (i in e) o[i] = e[i];
google.x(o,
function() {
gbar.tg(o)
})
}
};
if (google.y) google.y.first = [];
window.setTimeout(function() {
var xjs = document.createElement('script');
xjs.src = 'http://www.google.com/extern_js/f/CgJmciswCjgNLCswDjgELCswFjgELCswFzgBLCswGDgDLCswJTjJiAEsKzAnOAAs/4Pb8ykSjyRQ.js';
document.getElementsByTagName('head')[0].appendChild(xjs)
},
0);
google.y.first.push(
function(){
var google_suggest = document.getElementById('google_suggest');
google.ac.i(
google_suggest,
google_suggest.q,
'',
''
)
}
)
function _gjp() { ! (location.hash && _gjuc()) && setTimeout(_gjp, 500);
}
window._gjuc && _gjp();
});
wikipedia_action.php 的 PHP
<?php
$search_field = trim($_POST['wikipedia_field']);
$search_engine = trim($_POST['wikipedia']);
$url_params = preg_replace('/(\ )+/', '+', $search_field);
$url = array('wik_en'=>'http://en.wikipedia.org/wiki/Special:Search?search=', 'wik_fr'=>'http://fr.wikipedia.org/wiki/Special:Search?search=', 'wik_de'=>'http://de.wikipedia.org/wiki/Special:Search?search=', 'wik_ru'=>'http://ru.wikipedia.org/wiki/Special:Search?search=', 'wik_es'=>'http://es.wikipedia.org/wiki/Special:Search?search=');
header('Location:'.$url[$_POST['wikipedia']].$url_params)
?>
其实我有两个问题……</p>
1 - 我注意到谷歌建议将kHL:"en"更改为kHL:"fr"用于法语或kHL:"de"用于德语可以解决问题,但我不知道如何根据选中的单选按钮进行更改?(并且没有一些 onClick,jQuery 应该会更好)
2 - 我也未能建立维基百科建议系统,这就是我也在寻找这个(并且建议改变)的原因。它在这里使用:
http://en.wikipedia.org/wiki/Special:搜索
http://fr.wikipedia.org/wiki/Sp%C3%A9cial:Recherche
http://de.wikipedia.org/wiki/Spezial:Suche
等等。
任何帮助,将不胜感激 ;)