本文介绍了如何将数组的所有值显示到不同的输入文本区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
0
I have an array of objects having some questions and answers. The jQuery code shows the values of array outside the input fields but not inside it.
I want something like :
<pre>$('#input').append(this.question + "<br>");
我的尝试:
What I have tried:
<body>
<div id="container">
<h1> Press 'Enter' after writing your answer. </h1>
<input type="text" id="input" name="questions[]" />
<input type="text" id="output" />
<input type="text" id="input" name="questions[]" />
<input type="text" id="output" />
<input type="text" id="input" name="questions[]" />
<input type="text" id="output" />
<input type="text" id="input" name="questions[]" />
<input type="text" id="output" />
<input type="text" id="input" name="questions[]" />
<input type="text" id="output" />
<a id="sub" href="#"> Submit </a>
<div id="result"> </div>
</div>
</body>
<script>
$('document').ready(function() {
let questions = [
{
question: "1. I like tea.",
answer: "I do not like tea."
},
{
question: "2. You are my friend.",
answer: "You are not my friend."
},
{
question: "3. She is very naughty.",
answer: "She is not very naughty"
},
{
question: "4. You can do it.",
answer: "You cannot do it"
},
{
question: "5. They are good.",
answer: "They are not good."
},
];
$.each(questions, function() {
$('#result').append(this.question + "<br>");
});
});
</script>
推荐答案
我尝试过:
What I have tried:
<body>
<div id="container">
<h1> Press 'Enter' after writing your answer. </h1>
<input type="text" id="input" name="questions[]" />
<input type="text" id="output" />
<input type="text" id="input" name="questions[]" />
<input type="text" id="output" />
<input type="text" id="input" name="questions[]" />
<input type="text" id="output" />
<input type="text" id="input" name="questions[]" />
<input type="text" id="output" />
<input type="text" id="input" name="questions[]" />
<input type="text" id="output" />
<a id="sub" href="#"> Submit </a>
<div id="result"> </div>
</div>
</body>
<script>
这篇关于如何将数组的所有值显示到不同的输入文本区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!