jQuery get the selected dropdown value on change

后端 未结 6 1752
无人及你
无人及你 2021-01-17 17:51

I\'m trying to get the value of a dropdown on change (and then change the values in a second dropdown).

EDIT: Thanks for all the replies, i\'ve upda

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-17 18:09

    You can also obtain custom attributes from the dropdown as below;

         $('.someclass').change (function () { 
                  var val = this.value;
                  alert(val);                                       //selected value
    
                   var element = $(this).find('option:selected');  // assign selected element
                   var myTag = element.attr("aTag");              // get attribute by name
                   alert(myTag);
        });
    
    
    
    

提交回复
热议问题