带有开关和事件监听器的下拉框

时间:2016-03-23 16:52:10

标签: javascript events

我无法让这个eventListener与我的交换机一起工作。我的最终结果应该是一个包含数组中值的下拉列表,其中一个onChange事件提示相应数组位置的switch事件。它应该是类号的下拉列表,onChange事件显示类名。请帮忙!          

    <script>
    var bubagoo = document.getElementById('classes');
    bubagoo.addEventListener('change', changer, false);
    function changer (){
    var newChoice = bubagoo.value;
    }
        var classes = ["CME219", "CME306","CME308","CME419", "CME422"];
        var dropDownBox = "<select name='classes' id = 'classes'>";
        for (var i=0; i < classes.length; i++) {
        dropDownBox += "<option value =" + classes[i] + ">" + classes[i]
        </option>;
         }
switch (classes) {
case "CME219":
var text = ":Design for the Web";
    break;
case "CME306":
var text = ":Reponsive Design";
    break;
case "CME308":
var text = ":Interaction Design";
    break;
case "CME419":
var text = ":Interactive Development";
    break;
case "CME422":
var text = ":New Media Distribution";
    break;
default: 
var text ="Uh oh... something is on the fritz";
    break;
}
 dropDownBox+="</select>";
document.write(dropDownBox);
  </script>
</html>

0 个答案:

没有答案