[英]how to display data from textbox to another page?
I want to collect data in the form of a paragraph in the text box and then show that to a new page.我想在文本框中以段落的形式收集数据,然后将其显示到新页面。 I have added code for HTML for the announcement page (from where I want to take data and show it there as well), and for the archive page ( where I want to show the data), How should I do it?我已经为公告页面(我想从那里获取数据并在那里显示它)和存档页面(我想在哪里显示数据)添加了 HTML 代码,我应该怎么做? Kindly help me out.请帮帮我。 I am new to HTML therefore I am not sure if I am doing this the right.我是 HTML 新手,因此我不确定我这样做是否正确。
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="stylem.css" />
<script type="text/javascript" src="index.js"></script>
<head>
<title>Announcement Page</title>
</head>
<body>
<form method="Post" action="archive.html">
<textarea type="text" id="textbox" class="textbox" cols="40" rows="10"></textarea>
<input type="submit" id="save" name="save" value="submit" onclick="handleSubmit()"/>
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>
Archive
</title>
<link rel="stylesheet" href="stylea.css" />
</head>
<body>
<h2> Announcement : <span id="result-text"> </span> </h2>
</body>
</html>
function handleSubmit (){
const textbox = document.getElementById('textbox').value;
localStorage.setItem("Data", textbox);
return;
}
window.addEventListener('load', () => {
const params = (new URL(document.location)).searchParams;
const textbox = params.get('textbox');
document.getElementById('result-text').innerHTML= textbox;
})
You're putting your "Data" into local storage so you need to access it there instead of trying to pull it from the document location您将“数据”放入本地存储,因此您需要在那里访问它,而不是尝试从文档位置拉取它
window.addEventListener('load', () => {
const data = localStorage.getItem('Data');
document.getElementById('result-text').innerHTML = data;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.