Javascript 我能';你不能发到谷歌吗?
这是一个小程序的代码,你在其中输入关键字,选择搜索引擎,然后按“搜索”按钮进行搜索。但谷歌不会让我发帖。我还能做什么 编辑:雅虎和必应运作良好 错误 HTMLJavascript 我能';你不能发到谷歌吗?,javascript,html,Javascript,Html,这是一个小程序的代码,你在其中输入关键字,选择搜索引擎,然后按“搜索”按钮进行搜索。但谷歌不会让我发帖。我还能做什么 编辑:雅虎和必应运作良好 错误 HTML 谷歌 雅虎! 必应 Javascript <script type="text/javascript"> var searchengine=[ "http://google.com/search?q=", "http://search.yahoo.com/search?p=", "http://bing.com/sear
谷歌
雅虎!
必应
Javascript
<script type="text/javascript">
var searchengine=[
"http://google.com/search?q=",
"http://search.yahoo.com/search?p=",
"http://bing.com/search?q="
];
function redirect()
{
var radioButtons = document.getElementsByName("ch");
for (var x = 0; x < radioButtons.length; x++) {
if (radioButtons[x].checked)
{
document.search.action = searchengine[x] + document.search.keyword.value;
}
}
}
</script>
var搜索引擎=[
"http://google.com/search?q=",
"http://search.yahoo.com/search?p=",
"http://bing.com/search?q="
];
函数重定向()
{
var radioButtons=document.getElementsByName(“ch”);
对于(var x=0;x
“http:google.com/search?q=“
”的格式不正确
试试”http://google.com/search?q=“
”http:google.com/search?q=“
”的格式不正确
试试”http://google.com/search?q=“
但谷歌不会让我发帖。我还能做什么
在表单中使用GET
而不是POST
,或者只将相关URL分配给window.location
下面是后者的一个例子。其他一些变化:
- 添加了一些
s标签
- 更改了所选单选按钮与搜索引擎的匹配方式,以使其更加健壮/可维护
- 更改了搜索表单的名称。由于这会被转储到
对象中,所以我避免使用像“search”这样的简单单词窗口
- 正确编码关键字(必须对URI参数进行编码)
谷歌
雅虎!
宾
JavaScript:
var searchengine = {
"google": "http://google.com/search?q=",
"yahoo": "http://search.yahoo.com/search?p=",
"bing": "http://bing.com/search?q="
};
function doSearch() {
var frm, index, cb;
frm = document.searchForm;
if (frm && frm.ch) {
if (frm.ch) {
for (index = 0; index < frm.ch.length; ++index) {
cb = frm.ch[index];
if (cb.checked) {
window.location = searchengine[cb.value] +
encodeURIComponent(frm.keyword.value);
}
}
}
}
return false; // Cancels form submission
}
var搜索引擎={
“谷歌”:http://google.com/search?q=",
“雅虎”:http://search.yahoo.com/search?p=",
“必应”:http://bing.com/search?q="
};
函数doSearch(){
var frm,指数,cb;
frm=document.searchForm;
如果(frm和frm.ch){
如果(第一季度){
对于(索引=0;索引
但谷歌不会让我发帖。我还能做什么
在表单中使用GET
而不是POST
,或者只将相关URL分配给window.location
下面是后者的一个例子。其他一些变化:
- 添加了一些
s标签
- 更改了所选单选按钮与搜索引擎的匹配方式,以使其更加健壮/可维护
- 更改了搜索表单的名称。由于这会被转储到
对象中,所以我避免使用像“search”这样的简单单词窗口
- 正确编码关键字(必须对URI参数进行编码)
谷歌
雅虎!
宾
JavaScript:
var searchengine = {
"google": "http://google.com/search?q=",
"yahoo": "http://search.yahoo.com/search?p=",
"bing": "http://bing.com/search?q="
};
function doSearch() {
var frm, index, cb;
frm = document.searchForm;
if (frm && frm.ch) {
if (frm.ch) {
for (index = 0; index < frm.ch.length; ++index) {
cb = frm.ch[index];
if (cb.checked) {
window.location = searchengine[cb.value] +
encodeURIComponent(frm.keyword.value);
}
}
}
}
return false; // Cancels form submission
}
var搜索引擎={
“谷歌”:http://google.com/search?q=",
“雅虎”:http://search.yahoo.com/search?p=",
“必应”:http://bing.com/search?q="
};
函数doSearch(){
var frm,指数,cb;
frm=document.searchForm;
如果(frm和frm.ch){
如果(第一季度){
对于(索引=0;索引
虽然是真的,但从他得到的错误可以看出这不是问题所在。我只是抄错了东西。。。它固定在原来的。。。这不是问题虽然是真的,但从他犯的错误我们可以看出这不是问题。我只是抄错了东西。。。它固定在原来的。。。这不是问题problem@Loclip:GET
如果表单字段正确,则可以使用。具体来说,你的关键字
字段必须是q
,你必须从你提交的URL中删除q
,因为谷歌希望q
成为搜索词。哦,我明白了。。。但它更容易使用窗口。location@Loclip:在本例中,由于您仍然依赖JavaScript,是的。:-)如果不使用JavaScript(使用大致相同的UI),也可以使用聪明的CSS可见性选择器来执行此操作,但是用户必须在键入关键字之前选择搜索引擎(因为我们必须显示/隐藏包含关键字字段的不同表单)。可能有点奇怪。:-)@Loclip:GET
如果表单字段正确,则可以工作。具体来说,你的关键字
字段必须是q
,你必须从你提交的URL中删除q
,因为谷歌希望q
成为搜索词。哦,我明白了。。。但它更容易使用窗口。location@Loclip:在本例中,由于您仍然依赖JavaScript,是的。:-)如果不使用JavaScript(使用大致相同的UI),也可以使用聪明的CSS可见性选择器来执行此操作,但是用户必须在键入关键字之前选择搜索引擎(因为我们必须显示/隐藏包含关键字字段的不同表单)。可能有点奇怪。:-)
<form name="searchForm" action="" method="GET" onSubmit="return doSearch()">
<input type="text" name="keyword">
<br>
<label>Google<input type="radio" name="ch" value="google" checked></label>
<label>Yahoo!<input type="radio" name="ch" value="yahoo"></label>
<label>Bing<input type="radio" name="ch" value="bing"></label>
<br>
<input type="submit" value="Search">
</form>
var searchengine = {
"google": "http://google.com/search?q=",
"yahoo": "http://search.yahoo.com/search?p=",
"bing": "http://bing.com/search?q="
};
function doSearch() {
var frm, index, cb;
frm = document.searchForm;
if (frm && frm.ch) {
if (frm.ch) {
for (index = 0; index < frm.ch.length; ++index) {
cb = frm.ch[index];
if (cb.checked) {
window.location = searchengine[cb.value] +
encodeURIComponent(frm.keyword.value);
}
}
}
}
return false; // Cancels form submission
}