Bind click event on select option

前端 未结 7 1276
长情又很酷
长情又很酷 2021-01-17 21:54

I\'ve got a problem making a click event on an HTML option element work.

Even a simple console.log(\'hello!\'); won\'t work.

7条回答
  •  无人共我
    2021-01-17 22:03

    Sample example will show how to change dropdown values and color for the OPTION on click or change of select

    HTML:

    
    

    jQuery:

    $("select").on("click", function () {
        debugger;
        var sVal = $(this).val();
        $(this).css("background-color", "red");
        $(this).find("option").css("background", "white");
        $(this).find('option:selected').css("background-color", "red");
        $("input").val($(this).val());
    });
    

    Demo

提交回复
热议问题