How to get select box option value in jQuery

后端 未结 8 1673
逝去的感伤
逝去的感伤 2021-02-03 10:47

How to get the value of option select box in jQuery if I have the code like this,


                        
    
提交评论

  • 2021-02-03 11:21

    try this,

    jQuery(document).ready(function() {
    
        jQuery('#media').change(function(e) {
    
            var id = $(this,':selected').val();
            alert(id);
    
        });
    
    });
    
    0 讨论(0)
  • 2021-02-03 11:28

    use this code:

    $('#media').change(function(){
        alert($('#media :selected').val());// or $('#media').val();        
    });​
    
    0 讨论(0)
  • 2021-02-03 11:30
    $("#id option:selected").val();
    

    Here id is the id of a select box. I'm sure it will work 100%.

    If you want selected text use this one:

    $("#id option:selected").text();
    
    0 讨论(0)
  • 2021-02-03 11:32
    $('#media').change(function(){
    alert($(this).val());
    });
    

    this should work the way you want it should.

    0 讨论(0)
  • 2021-02-03 11:37

    make sure you use latest jquery because its working fine

    http://jsfiddle.net/Hayhv/

    check it give value of option

    0 讨论(0)
  • 提交回复
    热议问题