click event for option doesn't work in IE

前端 未结 7 2006
一整个雨季
一整个雨季 2020-12-16 21:11

I have a multiple select tag, and I need to write the function onclick of it\'s options, because I need to get the value of last clicked option, but when I wrote the followi

7条回答
  •  感情败类
    2020-12-16 22:16

    If you really want to have a click event on each option, you need to have List instead of a dropdown style.

    To accomplish that, add the size attribute into the select element for instance:

    ​​​​​​​​​​​​​​​​​​​​​​​​​
    

    Now you can bind each option individually.

    If you want to get the value of a clicked option use the change event handler and .val() method, like:

    $("#multiple_select").change(function() {
      var val = $(this).val();
      alert(val);
    });
    

提交回复
热议问题