javascript - 如何使用javascript使输入值显示在不同的页面中?
问题描述
我正在尝试使我的一个 html 页面中的输入值显示在我的另一个 html 页面中?
我的代码在第一页如下。
<div class="resume-input">
<h3>SUMMARY: </h3>
<textarea name="Summary" placeholder="If its more than 100 words no one is going to read it" id="textarea" cols="30" rows="10"></textarea>
</div>
这是我在页面中应该显示输入值的 html 代码
<div class="col-md-12">
<center>
<h1><div id="summary"></div></h1>
</center>
</div>
我的 JS 看起来像这样
document.querySelector('#button1').addEventListener('click', function(){
var summary = document.querySelector('#textarea').value;
var summaryInput = document.querySelector('#summary');
summaryInput.textContent = summary
window.location = 'results.html'
})
window.location = 'results.html' 允许按钮将输入值重定向到具有上一页输入值的另一个页面。
解决方案
在按钮上单击将值存储在localStorage中
localStorage.setItem("anyKeyName","here goes the value from textarea")
并在加载results.html
检索值
summaryInput.textContent = localStorage.getItem("anyKeyName")
也看看window.onload
推荐阅读
- java - 在 Java 中创建和解析非常大的数组
- tensorflow - 如何使用 TensorFlow 解决不同大小的 CNN 输入数据?
- excel - 为什么我不能隐藏进度条上的标题栏?
- r - 为每组中的每一行运行一个 wilcox 函数
- angular - 如何在垫表角材料中排序时显示确认
- java - 在 Spring 中动态设置 Java bean 验证消息
- javascript - 如何将当前时间与小时字符串 JavaScript 进行比较
- c - C : 打印值时的动态间距
- oracle - 将 NLS_SORT 更改为 BINARY_CI 时,Oracle 12c 和 18c 上的查询失败
- microsoft-graph-api - 通过 API 访问 OneDrive 个人保管库