我有一个在新窗口中打开的简单的 Google 图片搜索表单。当我想将表单参数更改为 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,输出
因此,如果您不向 unsplash.com 发送任何参数,请不要使用表单提交。相反,在 unsplash() 函数中使用 javascript 重定向。
window.location.href = "https://unsplash.com/search/photos/";
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)