addEventListener, “change” and option selection

前端 未结 2 1251
长发绾君心
长发绾君心 2020-12-07 23:57

I\'m trying to have dynamic select list populate itself, from a single selection to start:


                        
    
提交评论

  • 2020-12-08 00:53

    The problem is that you used the select option, this is where you went wrong. Select signifies that a textbox or textArea has a focus. What you need to do is use change. "Fires when a new choice is made in a select element", also used like blur when moving away from a textbox or textArea.

    function start(){
          document.getElementById("activitySelector").addEventListener("change", addActivityItem, false);
          }
    
    function addActivityItem(){
          //option is selected
          alert("yeah");
    }
    
    window.addEventListener("load", start, false);
    
    0 讨论(0)
  • 提交回复
    热议问题