“onchange”处理程序“undefined不是函数”错误

时间:2015-04-13 19:09:37

标签: javascript jquery onchange

我有一个下拉列表(<select id="typeselect">),其中包含一个内联onchange事件处理程序,用于提醒所选选项。为什么我会收到错误:undefined is not a function

以下演示:

&#13;
&#13;
(function($) {

  function test() {
    var selected_option = $('#typeselect option:selected');
    alert(selected_option);
  }

})(jQuery);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="typeselect" onchange="test()">
  <option>(Select)</option>
  <option value="oi">Outgoing invoice</option>
  <option value="ii">Incoming invoice</option>
  <option value="oc">Outgoing Credit Nota</option>
  <option value="ic">Incoming Credit Nota</option>
</select>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

谢谢showdev的答案!并感谢其他人提供的帮助!

    $('#typeselect').on('change',test});

工作得很好! :d