首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >删除查询字符串"?“在HTML表单中,方法GET

删除查询字符串"?“在HTML表单中,方法GET
EN

Stack Overflow用户
提问于 2018-06-24 01:36:07
回答 2查看 2.3K关注 0票数 1

我有一个简单的谷歌图片搜索表单,在一个新窗口中打开。当我想要将表单参数更改为Unsplash (在URL搜索中不使用查询字符串)时,表单将继续发送查询字符串;(

HTML

代码语言:javascript
运行
复制
<input type="radio" id="google" name="image" onclick="googleImages();" checked/>
<label for="google">Google Images</label>

<input type="radio" id="unsplash" name="image" onclick="unsplash();"/>
<label for="unsplash">Unsplash</label>

<form id="form" method="GET" action="https://www.google.com/search?q=">
    <input id="input" type="text" name="q" value="" required>
    <input type="submit" value="Search" onclick="this.form.target='_blank';">
    <input id="helper" type="hidden" name="tbm" value="isch">
</form>

JS

代码语言:javascript
运行
复制
var
  form = document.getElementById("form"),
  input = document.getElementById("input"),
  helper = document.getElementById("helper");

function googleImages() {
  form.action="https://www.google.com/search?q=";
  input.name="q";
  helper.name="tbm";
  helper.value="isch";
}
function unsplash() {
  form.action="https://unsplash.com/search/photos/";
  input.name="";
  helper.name="";
  helper.value="";
}

如何创建从输出URL中删除查询字符串函数?(并在单选选项需要参数时重新设置参数)

请参阅此处的代码:http://jsbin.com/qitadepoxu/1/edit?html,js,output

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51003560

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档