JQuery detect dropdown value is selected even if it's not changed

前端 未结 7 1792
感动是毒
感动是毒 2021-01-05 01:29

Using JQuery or JavaScript, I want to detect when a user selects a value, even if they don\'t change the already selected value.

How can this be accomplished?

<
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-05 02:09

    Try this...

    To get selected option's value...

    $("body").click(function(event) {
        if(event.target.nodeName== "SELECT"){
                     selectedValue = event.target.value;
                }   
    });
    

    and then get the text from the value

    var text = $("option").filter(function() {
          return $(this).attr("value") === selectedValue;
        }).first().text();
    

提交回复
热议问题