Javascript 如何将变量从index.html文件加载到results.html文件?
我正在尝试创建某种搜索引擎,我已经设置了输入,但是我需要将搜索到的tearm加载到我的结果页面中,我使用javascript进行此操作,1个页面用于输入,一个文件用于存储数据,1个文件用于输出数据 输入:Javascript 如何将变量从index.html文件加载到results.html文件?,javascript,html,Javascript,Html,我正在尝试创建某种搜索引擎,我已经设置了输入,但是我需要将搜索到的tearm加载到我的结果页面中,我使用javascript进行此操作,1个页面用于输入,一个文件用于存储数据,1个文件用于输出数据 输入: var inputBox = document.getElementById("input-box"); var searchButton = document.getElementById("search-button"); var input = ""; searchButton.onc
var inputBox = document.getElementById("input-box");
var searchButton = document.getElementById("search-button");
var input = "";
searchButton.onclick = function() {
input = inputBox.value;
input = input.toLowerCase();
console.log("Input: " + input);
getData(input);
}
数据存储:
var storeSearchedTearm = "";
getData = function(whatToStore) {
console.log("Database collection: " + whatToStore);
storeSearchedTearm = whatToStore;
console.log("Database added to store: " + storeSearchedTearm);
}
输出:
console.log("Data: " + storeSearchedTearm);
var searchedTearm = "";
searchedTearm = storeSearchedTearm;
console.log("Output: " + searchedTearm);
按下index.html中的搜索按钮后,可以将搜索到的查询存储在Localstorage中,并在results.html中获取该值。试试我的解决办法 Index.html
var inputBox = document.getElementById("input-box");
var searchButton = document.getElementById("search-button");
var input = "";
searchButton.onclick = function() {
input = inputBox.value;
input = input.toLowerCase();
console.log("Input: " + input);
localStorage.setItem("searchedQuery",input );
getData(input);
}
Results.HTML或任何要查看保存数据的位置:
var SearchedQuery = localStorage.getItem("searchedQuery");
你的问题是…?这能回答你的问题吗?你是如何进行搜索的?如果它在服务器上,则使用POST将搜索字符串发送给它。