為什麼當我使用val()設定select的值時,jquery change事件不會觸發?(轉)

  • 81
  • 0

為什麼當我使用val()設定select的值時,jquery change事件不會觸發?(轉)

<select id="single">
<option>Single</option>
<option>Single2</option>
</select>

<script>
$(function() {
$(":input#single").change(function() {
/* Logic here does not execute when val() is used */
});
});

$("#single").val("Single2");
</script>

$("#single").val("Single2").change();

 

https://www.codetw.com/elyc.html