click event for option doesn't work in IE

前端 未结 7 1983
一整个雨季
一整个雨季 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:

    <select type="multiple" size=4>
      <option>foo</option>
      <option>bar</option>
      <option>baseball</option>
    </select>​​​​​​​​​​​​​​​​​​​​​​​​​
    

    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);
    });
    
    0 讨论(0)
提交回复
热议问题