我有一个简单的谷歌图片搜索表单,在一个新窗口中打开。当我想要将表单参数更改为Unsplash (在URL搜索中不使用查询字符串)时,表单将继续发送查询字符串;(
HTML
<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
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
https://stackoverflow.com/questions/51003560
复制相似问题