【问题标题】:saving user input to array将用户输入保存到数组
【发布时间】:2017-01-05 03:32:58
【问题描述】:

我正在为我的课程分配一个作业。当单击“提交”按钮时,我必须将用户输入(来自 9 个数学问题的答案)保存到一个数组中,然后使用该数组执行检查有多少答案是正确的和显示命中率等功能。我已经用表格和表单组合编写了 html,但不知道如何从 javascript 开始。 谢谢!

【问题讨论】:

  • 数组可以使用[] 进行实例化 ... 添加到使用.push ... 有一个开始
  • stackoverflow.com/questions/10523200/… 这应该可以帮助您入门
  • 如果你要在这里问,可以添加好分享你的html到目前为止。

标签: javascript html arrays input


【解决方案1】:

像这样为所有文本框提供 id 我已经包含了一个文本框,你可以包含多少你想要的

<input name="text" type="text" maxlength="512" id="answer1" />

<button onclick="myFunction()">Submit</button>
function myFunction(){
var array= [];
var value = document.getElementById('answer1').value
array.push(value);
for(int i=0; i< array.length; i++){
    //perform your operations
}}

【讨论】:

    猜你喜欢
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 2017-05-21
    • 2015-04-25
    • 1970-01-01
    相关资源
    最近更新 更多