Tarun Rathore Ответов: 0

Как отобразить все значения массива в разные области ввода текста?


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>");




Что я уже пробовал:

<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>

Gerry Schmitz

Я думаю, что смысл "имен" (и идентификаторов?) заключается в том, что они уникальны.

0 Ответов