javascript - 有什么办法可以在一个表单中使用多个输入?
问题描述
我在做我的项目时遇到了麻烦。在我的项目中,我在 HTML 中进行谷歌高级搜索,我需要 4 个字段。这 4 个字段是用户输入,其中指定了他们在搜索中想要的边界。当用户点击 google 搜索时,它会在 javascript 中执行 result() 操作。结果从文本框中获取这些输入并将其存储为变量并调用警报。我的问题是如何获取我在 javascript 中形成的字符串并将其用作 google 搜索的表单响应。
function result() {
var atw = document.getElementById("aTW").value;
var ewp = document.getElementById("eWP").value;
var tw = document.getElementById("tW").value;
var ntw = document.getElementById("nTW").value;
var string = atw + " " + tw + " " + "\"" + ewp + "\"" + " " + "-" + ntw;
alert(string);
}
<h3>Advanced Search</h3>
<form action="https://www.google.com/search">
<p>
<label>All these words</label>
<input type = "text"
id = "aTW"
value = ""/>
</p>
<p>
<label>this exact word or phrase:</label>
<input type = "text"
id = "eWP"
value = "" />
</p>
<p>
<label>any of these words:</label>
<input type = "text"
id = "tW"
value = "" />
</p>
<p>
<label>none of these words:</label>
<input type = "text"
id = "nTW"
value = "" />
</p>
<input type="text" name ="q" id = "inputs" placeholder="Search">
<input onclick = "result()" type="submit" value="Google Search">
</form>
解决方案
how can I take the string I formed in javascript and use it as the form response for the google search.
将您的谷歌搜索查询形成为您的字符串,然后将查询发送到谷歌搜索页面......
function googleSearch(query){
url = 'http://www.google.com/search?q=' + query;
window.open(url, '_blank');
}
在你的 result() 函数中调用你的函数进行谷歌搜索......
function result() {
var atw = document.getElementById("aTW").value;
var ewp = document.getElementById("eWP").value;
var tw = document.getElementById("tW").value;
var ntw = document.getElementById("nTW").value;
var string = atw + " " + tw + " " + "\"" + ewp + "\"" + " " + "-" + ntw;
alert(string);
googleSearch(string);
}
推荐阅读
- mysql - 将 NON NULL 与 NULL 值连接
- r - 如何 rbind() / dplyr::bind_rows() / data.table::rbindlist() 包含数据框列的数据框?
- python - 泰勒级数 - 当 T1 == T0 时如何停止该功能?
- javascript - 如何获取浏览器支持的所有 HTML 元素标签的列表
- c# - 没有输入 DateTimePicker 时出现实体错误
- python - 从 TTF 文件安装字体
- objective-c - AdMob 测试 广告显示,但有一个下载按钮。任何人都知道为什么会这样
- c++ - C++ 资源文件 ProductVersion 显示变量名称而不是变量值
- python - 当我只给它一个目录时,为什么错误专门命名一个文件时出现“FileNotFoundError”
- grails - 如何注册自定义约束