编写一个javascript函数,只需在单击按钮时将表单的详细信息打印到另一个html页面
Writing a javascript function that just prints details of a form to another html page when a button is clicked.
所以我试图从表单中获取信息,一个是用户可以更改的数字,另一个是常量浮点数字。当用户输入一个数字时,他们会按提交,也就是我希望输出打印到我的确认网页上的时候。我在网上没有看到太多关于这方面的内容,所以如果有人能给我一些建议,或者只是为我提供一些在线材料,我将不胜感激。还应该提到的是,我不允许使用任何javascript库来做这件事,以防万一。感谢
啊,我感到很同情。我认为你是在同一个页面上做这件事的(如果不是,你可能在错误的地方&我想你想要PHP)。
如果是这样的话,这里有一些非常粗糙的东西让你开始,并附上一些评论。
请注意,关于JS和DOM有大量的信息,因为它本质上是该语言的主要目的。这表明你看起来并不是很认真,但我知道一开始很难知道你在找什么。MDN通常在细节方面非常出色——看看这里使用的方法,它们都会有比我更好的例子。
// Listen for a 'click' on the element with an ID of 'submit',
// and run the 'printSomeCrap' function:
document.querySelector('#submit').addEventListener('click', printSomeCrap, false)
function printSomeCrap() {
// Grab the constant from the element with the id 'constant'
var constant = document.querySelector('#constant').textContent
// Grab whatever was typed in from the element with the id 'input'
var input = document.querySelector('#input').value
// Then find the element with the ID of 'output', and print out
// what was just grabbed as a string:
document.querySelector('#output').innerHTML = `Constant: ${constant}, Input: ${input}`
}
<input id="input" type="text" placeholder="Just type something">
<p id="constant">0.123456789</p>
<button id="submit">Then press this button</button>
<div id="output"></div>
相关文章:
- 单击禁用表单按钮,然后提交表单
- 如何将POST表单按钮转换为链接
- 按下iframe内部的Youtube订阅表单按钮
- 表单按钮在同一窗口中打开新的URL
- 按下Youtube订阅表单按钮
- 表单按钮上的页面转换
- 禁用表单按钮,除非已填写所有文本输入字段
- 如何查看从 javascript 中的表单按钮提交调用的 php 文件中的回显
- 从“onblur”事件中排除表单按钮,JavaScript
- 触摸启动时显示为灰色的表单按钮
- 如何在表单按钮中使用JavaScript函数
- HTML5表单按钮提交不起作用
- 刮擦:找不到表单按钮
- 保留未保存的表单:按钮提交事件将重置“Changed_Form”状态
- 无法阻止追加在 Jquery UI 对话框上的表单按钮的缺省操作
- iframe 中的表单按钮,单击后,在父窗口中加载
- 在表单按钮css中的文本旁边添加图像
- 使用JavaScript提交特定的表单按钮
- 提交表单按钮在ajax发布后卡住
- 使表单按钮在单击后消失(游戏)