基本上,我得到了一项任务,用户必须将数据输入到HTML
文件中的字段中。当输入所有细节时,用户要点击一个按钮,然后打开一个新窗口(而不是选项卡(&显示基于用户输入的结果以及附加细节。
在body标签中,我使用了<button type="button" onClick="Acknowledge()" > </button>
这应该在函数中执行。
function(Acknowledge(){
//code to display results from inputted fields
}
我需要做什么才能在新窗口中显示功能的结果(这显然不会导致新网站(?我想我需要另一个.html
文件来显示结果,但不知道如何将结果放入新文件中。
u可以使用一个新的.html文件,该文件从url中获取结果。在当前文件中,您需要window.open方法来打开一个新的选项卡。当前文件:
window.open('http://youdomain.com/another.html?result=your result');
another.html:
function getResult(){
const search = location.search.substr(1);
let result = '';
if(search.length > 0){
search.split('&').forEach((str) => {
const [key,value] = str.split("=");
if(key === 'result'){
result = value;
}
})
}
return result;
}