我正在尝试在一个页面上输入一个输入,比方说,用户输入他们的名字,然后单击提交按钮,它会将他们带到另一个页面,其中显示Hello“name”。
我似乎让它工作,但是当我尝试另一个页面时,它没有输入。
有没有办法在一个页面上完成所有操作?我不希望输出显示。如果它是一个页面,我想进行转换,所以它就像一个全屏输入名称:然后将转换提交到一个带有Hello,“name”的新屏幕。
我到目前为止的代码:
<input id="txtOutput">
新页面
#include <stdio.h>
#include <string.h>
#include "mp1_lib.h"
int main()
{
int n;
printf("\n");
printf("Input n: ");
scanf("%d", &n);
n += 1;
char words[n][16];
initialize(n, words);
get_words(n, words);
print_words(n, words);
printf("\n");
}
void initialize(int n, char words[][16])
{
for (int x=0; x < n; x++)
{
for(int y=0; y < 16; y++)
{
words[x][y] = ' ';
}
}
}
void get_words(int n, char words[][16])
{
char c;
char check = '0';
for(int x = 0; x < n; x++)
{
int y = 0;
while (check != '\0' && y < 16)
{
c = getchar();
words[x][y] = c;
check = c;
y++;
}
}
}
void print_words(int n, char words[][16])
{
for(int x=0; x < n; x++)
{
for(int y=0; y < 16; y++)
{
putchar(words[x][y]);
}
}
}
答案 0 :(得分:2)
查看localstorage API。 Localstorage允许您在浏览器中存储数据,如下所示:
localStorage.setItem('item1', 'value1');
您可以稍后像这样的数据访问,如下所示:
let cat = localStorage.getItem("item1");
答案 1 :(得分:1)
您需要将第1页的值发送到第2页。在您的情况下,您将在第1页中执行脚本并将用户带到第2页,其中整个页面再次加载。你执行的脚本消失了。
你的Page1.html
<label>Type your name: </label>
<input type="text" id="txtName">
<input type="button" value="click me" onclick="transfer()">
<script>
function transfer() {
location.href = "output.html?name="+document.getElementById("txtName").value;
}
</script>
现在,您的用户将被带到output.html?name = {他已输入的名字}
output.html:
<input id="txtOutput">
<script>
// function to get data from URL.
function findGetParameter(parameterName) {
var result = null,
tmp = [];
var items = location.search.substr(1).split("&");
for (var index = 0; index < items.length; index++) {
tmp = items[index].split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
}
return result;
}
document.getElementById("txtOutput").value = "Hi "+findGetParameter("name");
</script>
如果有帮助,请告诉我。但是,我建议您了解back_end技术的工作原理。并查看本地存储。