如何修改此项以将两个文本框值添加到URL。
//to add append single input value.
function filter(){
var myInput1 = document.getElementById('myInput1').value;
var searchType="fileName"
var appl="www.google.com/search/?"+searchType+"="+myInput1;
console.log(appl);
myInput1.href =appl;
myInput1.innerHTML = myInput1.href;
window.location = "www.google.com/search/?"+searchType+"="+myInput1;
}
提前致谢。
答案 0 :(得分:0)
您可以创建一个包含参数名称和值的映射的数组,然后将所有内容连接在一起以获取查询字符串,如:
var parameters = [
[ "fileName", document.getElementById('myInput1').value ],
[ "otherInput", document.getElementById('myInput2').value ]
];
var query = parameters.map(function(couple) {
return couple.join("=");
}).join("&");
// if you can use ES6 can be shorter, like:
// var query = parameter.map(couple => couple.join("=")).join("&");
var url = "www.google.com/search/?" + query;