烧瓶未获取javascript动态创建的元素

时间:2018-11-16 22:37:25

标签: javascript flask

我尝试使用带有flask.request.form.getlist()的列表获取列表,但是,我在html中创建的列表是这样的

<select multiple="multiple" class="form-control col-lg-5" name="question_list" id="question_list">

 </select>

有一个按钮,当我按下它时,它会向选择列表中添加选项

function add_question(){
   var question = document.getElementById('question').value;
   var question_list = document.getElementById('question_list');
   var all_options = question_list.options;
   var add = true;
    for(var i=0; i < all_options.length; i++)
     {
        if(all_options[i].value == question){
             alert("The question does already exist!!");
             document.getElementById('question').value ='';
                add= false;  // We do not need to create option
                break;
        }
     }
     if(add){
      // Need to add new question
         var option = document.createElement("option");
         option.value = question.trim();
         option.text = question.trim();
         question_list.add(option);
         
         document.getElementById('question').value ='';
         // Toggle Remove question button
         document.getElementById('remove_question').classList.contains('disabled');
         document.getElementById('remove_question').classList.remove("disabled");
         document.getElementById('remove_question').disabled = false;
      }
        var trigger = new Event('change');
        document.getElementById('question').dispatchEvent(trigger);
}

但是当我尝试使用request.form.getlist(“ question_list”)来获取列表时,我总是得到一个空列表,我以为Flask无法获取由javascript创建的动态创建的元素,有人可以帮助我

0 个答案:

没有答案