Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在HTML页面上动态填充列表_Javascript_Html - Fatal编程技术网

Javascript 如何在HTML页面上动态填充列表

Javascript 如何在HTML页面上动态填充列表,javascript,html,Javascript,Html,在提出这个问题之前,我探讨了如何将元素动态添加到列表中的现有答案,并将其中的几个元素合并到我尝试的解决方案中,以满足我的需要。然而,该列表似乎从未被填充。我认为问题可能与访问要附加元素的列表有关,但我不能完全确定 我的HTML: <div class="row" id="row"> <div class="col-sm-4" id="faculty"> <h3> Faculty Decks </h3> <ul id="facu

在提出这个问题之前,我探讨了如何将元素动态添加到列表中的现有答案,并将其中的几个元素合并到我尝试的解决方案中,以满足我的需要。然而,该列表似乎从未被填充。我认为问题可能与访问要附加元素的列表有关,但我不能完全确定

我的HTML:

<div class="row" id="row">
<div class="col-sm-4" id="faculty">
    <h3> Faculty Decks </h3>
    <ul id="faculty_list"> </ul>
</div>
<div class="col-sm-4">
    <h3> Instructions </h3>
    <p> Select your decks, select front (questions) or back (answers) of the the card and start studying. </p>
<div>
    <input class="front" type="radio" name="card" id="front" value="Front"> Front &ensp;</input>
    <input class="back" type="radio" name="card" id="back" value="Back"> Back</input>
    <br />
    <br />
    <button> Start Studying </button>
</div> 
</div>
<div class="col-sm-4" id="student">
    <h3> Student Decks </h3>
    <ul id="student_list"> </ul>
</div>

教员甲板
    说明书 选择你们的牌组,选择卡片的正面(问题)或背面(答案),然后开始学习

    前端和ensp; 返回

    开始学习 学生甲板
      我在HTML文件的其他地方调用Javascript函数,并且我已经确认调用了该函数,参数是我所期望的,循环运行了适当的次数

      这是我的Javascript函数:

      function populateLists(json) {
          for (var i = 0; i < json.length; i++){
              //Create a new list element
              var list_item = document.createElement('li');   
              list_item.setAttribute('name', json[i].name);
      
              //Create the checkbox to add to the list element
              var select_checkbox = document.createElement('input');
              select_checkbox.type = 'checkbox';
              select_checkbox.id = json[i].deck_ID;
      
              //Add the checkbox to the list element
              list_item.appendChild(select_checkbox);
      
              var list = document.getElementById('row').getElementById((json[i].faculty=='1')?'faculty':'student' + '_list');
      
              list.append(list_item);
          }
       }
      
      函数populateList(json){
      for(var i=0;i
      给你

      var json={'a':'First','b':'Second','c':'Third'};
      函数makeUL(json){
      //创建列表元素:
      var list=document.createElement('ul');
      for(var i=0;i
      
      给你

      var json={'a':'First','b':'Second','c':'Third'};
      函数makeUL(json){
      //创建列表元素:
      var list=document.createElement('ul');
      for(var i=0;i
      
      它似乎没有找到正确的列表。我遇到了一个错误,即无法链接getElementById调用,因此我改用queryselector。为了便于阅读,我还列出了列表名称

      函数populateList(json){
      for(var i=0;i
      
      
      教员甲板
      
        说明书 选择你们的牌组,选择卡片的正面(问题)或背面(答案),然后开始学习

        前端和ensp; 返回

        开始学习 学生甲板

          它似乎没有找到正确的列表。我遇到了一个错误,即无法链接getElementById调用,因此我改用queryselector。为了便于阅读,我还列出了列表名称

          函数populateList(json){
          for(var i=0;i
          
          
          教员甲板
          
            说明书 选择你们的牌组,选择卡片的正面(问题)或背面(答案),然后开始学习

            前端和ensp; 返回

            开始学习 学生甲板

              如果没有
              对象,我会这样做。键

              var dataObj={'a':'First','b':'Second','c':'Third'};
              函数创建