Click event on select option element in chrome

前端 未结 13 1127
闹比i
闹比i 2020-11-22 11:38

I\'m having a problem in Chrome with the following:

var items = $(\"option\", obj);  

items.each(function(){

    $(this).click(function(){

           


        
13条回答
  •  醉梦人生
    2020-11-22 11:56

    I use a two part solution

    • Part 1 - Register my click events on the options like I usually would
    • Part 2 - Detect that the selected item changed, and call the click handler of the new selected item.

    HTML

    
    

    JS

    $("#select-item-1").click(function () { alert('hello') });
    $("#select-item-2").click(function () { alert('world') });
    
    $("#sneaky-select").change(function ()
    {
       $("#sneaky-select option:selected").click();
    });
    

提交回复
热议问题