gpt4 book ai didi

javascript - 我不能发布到谷歌?

转载 作者:行者123 更新时间:2023-11-30 10:38:24 26 4
gpt4 key购买 nike

这是一个小程序的代码,您可以在其中输入关键字,选择搜索引擎,然后按“搜索”按钮进行搜索。但是谷歌不让我发帖。我还能做什么?

编辑:Yahoo 和 Bing 工作正常。

错误

405. That’s an error.

The request method POST is inappropriate for the URL
/search?q=computer. That’s all we know.

HTML

<form name="search" action="" method="Post" onSubmit="redirect()">
<input type="text" name="keyword"><br />
Google<input type="radio" name="ch" checked>
Yahoo!<input type="radio" name="ch">
Bing<input type="radio" name="ch"><br />
<input type="submit" value="Search">
</form>

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>

最佳答案

But google don't leave me to POST. What else I can do?

在您的表单中使用GET 而不是POST,或者只是将相关的URL 分配给window.location

这是后者的一个例子。其他一些变化:

  • 添加了一些标签
  • 更改了匹配所选单选按钮和 搜索引擎 的方式,使其更健壮/更易于维护。
  • 更改了搜索表单的名称。因为这会被转储到 window 对象上,所以我避免使用像“搜索”这样的简单词。
  • 正确编码关键字(您必须对 URI 参数进行编码)。

Live copy | Live source

HTML:

<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>

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
}

关于javascript - 我不能发布到谷歌?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12704794/

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