<legend id='8G3Zj'><style id='8G3Zj'><dir id='8G3Zj'><q id='8G3Zj'></q></dir></style></legend>

    <small id='8G3Zj'></small><noframes id='8G3Zj'>

  1. <tfoot id='8G3Zj'></tfoot>
        <bdo id='8G3Zj'></bdo><ul id='8G3Zj'></ul>
    1. <i id='8G3Zj'><tr id='8G3Zj'><dt id='8G3Zj'><q id='8G3Zj'><span id='8G3Zj'><b id='8G3Zj'><form id='8G3Zj'><ins id='8G3Zj'></ins><ul id='8G3Zj'></ul><sub id='8G3Zj'></sub></form><legend id='8G3Zj'></legend><bdo id='8G3Zj'><pre id='8G3Zj'><center id='8G3Zj'></center></pre></bdo></b><th id='8G3Zj'></th></span></q></dt></tr></i><div id='8G3Zj'><tfoot id='8G3Zj'></tfoot><dl id='8G3Zj'><fieldset id='8G3Zj'></fieldset></dl></div>

      如何在javascript中的ul中附加一个数组?

      how to append an array inside a ul in javascript?(如何在javascript中的ul中附加一个数组?)
        <tbody id='TXrWE'></tbody>
          • <bdo id='TXrWE'></bdo><ul id='TXrWE'></ul>
              <i id='TXrWE'><tr id='TXrWE'><dt id='TXrWE'><q id='TXrWE'><span id='TXrWE'><b id='TXrWE'><form id='TXrWE'><ins id='TXrWE'></ins><ul id='TXrWE'></ul><sub id='TXrWE'></sub></form><legend id='TXrWE'></legend><bdo id='TXrWE'><pre id='TXrWE'><center id='TXrWE'></center></pre></bdo></b><th id='TXrWE'></th></span></q></dt></tr></i><div id='TXrWE'><tfoot id='TXrWE'></tfoot><dl id='TXrWE'><fieldset id='TXrWE'></fieldset></dl></div>

                <small id='TXrWE'></small><noframes id='TXrWE'>

              1. <legend id='TXrWE'><style id='TXrWE'><dir id='TXrWE'><q id='TXrWE'></q></dir></style></legend>
              2. <tfoot id='TXrWE'></tfoot>
                本文介绍了如何在javascript中的ul中附加一个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在将名为短语的数组附加到名为 addPhraseToDisplay() 的方法时遇到问题.这是数组:

                I am having trouble appending an array called phrases to a method called addPhraseToDisplay(). Here is the array:

                class Game {
                constructor() {
                    this.missed = 0; // this property will be used as a counter for the total of 5 tries
                    this.phrases = ["life is strange","success does not come easy", "seven swans swimming", "guess the word", "wild goose chase"] 
                }
                

                我想要做的是将数组作为列表项附加到其中,我试图定位像这样的短语 newListItem.textContent = (this.phrases);,但这不起作用

                what I want to do is append the array into as list items, I tried to target the phrases like this newListItem.textContent = (this.phrases);, but that didn't work

                addPhraseToDisplay() {
                   //Create a reference to ul element
                    const myList = document.getElementById('myList');
                
                    //Crete new list items
                    let newListItem = document.createElement('li');
                    newListItem.textContent = (this.phrases);
                

                这是 html 代码,我希望将数组作为列表项放入其中

                this is html code where I would like the array to be inside as list items

                <!--My phrases need to be appended down here, div is parent element -->
                        <div id="phrase" class="section">
                            <ul id="myList">
                
                            </ul>
                

                如果有人可以帮助我将不胜感激

                if someone could help I would appreciated

                推荐答案

                <html>
                <body>
                
                <ul id="myList">
                
                </ul>
                
                <p>Click the button to append the array to the end of the list.</p>
                
                <button onclick="myFunction()">Try it</button>
                
                <script>
                var myPhrases = ["Phrase 1", "Phrase 2", "Phrase 3", "Phrase 4", "Phrase 5"]
                function myFunction() {
                    //Creating element with html tag .... and append it to another element
                    for (i = 0; i < myPhrases.length; i++)
                    {
                      var node = document.createElement("li");
                      var textnode = document.createTextNode(myPhrases[i]);
                      node.appendChild(textnode);
                      document.getElementById("myList").appendChild(node);
                    }
                }
                
                </script>
                
                
                </body>
                

                前面的 for 循环示例.

                Previous example with for loop.

                这篇关于如何在javascript中的ul中附加一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                Ordinals in words javascript(javascript中的序数)
                    <tfoot id='uNg5h'></tfoot>
                      <tbody id='uNg5h'></tbody>
                  1. <i id='uNg5h'><tr id='uNg5h'><dt id='uNg5h'><q id='uNg5h'><span id='uNg5h'><b id='uNg5h'><form id='uNg5h'><ins id='uNg5h'></ins><ul id='uNg5h'></ul><sub id='uNg5h'></sub></form><legend id='uNg5h'></legend><bdo id='uNg5h'><pre id='uNg5h'><center id='uNg5h'></center></pre></bdo></b><th id='uNg5h'></th></span></q></dt></tr></i><div id='uNg5h'><tfoot id='uNg5h'></tfoot><dl id='uNg5h'><fieldset id='uNg5h'></fieldset></dl></div>
                    • <bdo id='uNg5h'></bdo><ul id='uNg5h'></ul>

                      • <legend id='uNg5h'><style id='uNg5h'><dir id='uNg5h'><q id='uNg5h'></q></dir></style></legend>

                        <small id='uNg5h'></small><noframes id='uNg5h'>